I was wondering if it is possible to create a user-defined function that can take a parameter of varying length (as well as other parameters).
Essentially I want to pass a parameter that then gets used in an IN
statement. What I would like to do is have something like this:
CREATE FUNCTION ufnGetOpenNotificationValue
(@LegacyTypeID INT,
@MonthEnd DATE,
@YearStart DATE,
@YearEnd DATE)
Where @LegacyTypeID
is a list of integers.
So then using the function might look something like this
SELECT RE_Auxiliary.dbo.ufnGetOpenNotificationValue
((1,2,3),'2014-07-31','2013-09-01','2014-08-31')
rather than
SELECT RE_Auxiliary.dbo.ufnGetOpenNotificationValue
(1,'2014-07-31','2013-09-01','2014-08-31') +
RE_Auxiliary.dbo.ufnGetOpenNotificationValue
(2,'2014-07-31','2013-09-01','2014-08-31') +
RE_Auxiliary.dbo.ufnGetOpenNotificationValue
(3,'2014-07-31','2013-09-01','2014-08-31')
but if I try and pass multiple integers I get an error stating
Incorrect syntax near ','