i wondering if possible create user-defined function can take parameter of varying length (as other parameters).
essentially want pass parameter gets used in in
statement. have this:
create function ufngetopennotificationvalue (@legacytypeid int, @monthend date, @yearstart date, @yearend date)
where @legacytypeid
list of integers.
so using function might 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 try , pass multiple integers error stating
incorrect syntax near ','
as alex k states can't pass arrays input sql function. can pass table types (pass table parameter).
create type tabletype table (legacytypeid int) create function ufngetopennotificationvalue (@legacytypeid tabletype, @monthend date, @yearstart date, @yearend date) ... column_name in (select legacytype @legacytypeid)
you need insert tabletype variable before calling function variable passed parameter
another option pass in list in comma separated list of values. , use function (like one) use in clause
create function ufngetopennotificationvalue (@legacytypeid nvarchar(256), @monthend date, @yearstart date, @yearend date) ... column_name in (select val dbo.f_split(@stringparameter, ','))
which call this:
select re_auxiliary.dbo.ufngetopennotificationvalue ('1,2,3','2014-07-31','2013-09-01','2014-08-31')
Comments
Post a Comment