I have a report that use a multi-value parameter into a “in” statement in a query. For example (with @areas as the multi-value parameter):
select * from regions where areas in (@areas)
It works perfectly but now I need to send the same parameter to a function in the SQL Server 2005 database:
select name, myFunction(@areas) from regions where areas in (@areas)
The @areas parameter in the function are going to be used in a “in” statement as well. I tried to receive it with a varchar parameter but this causes an error. When I use the SQL Profiler, I see that the parameter is passed in this format:
N''1'',N''2'',N''3''
The specific questions here are, what data type the function parameter @areas must be? And how can I use that parameter into a “in” statement in the function?
Thanks
Generally if you are going to be passing in a list of some type as a parameter, you are going to want to pass it in as a varchar of a large enough length to handle the entirety of it. You could also pass it in as an XML parameter, but I’ve always preferred using the varchar route and parsing it that way.