Jeremy Stein - Brain
« No distinguished name in entry | Web Hosting Information » |
SQL Server T-SQL stored procedure in-clause list from parameter
I tried to do this in a T-SQL stored procedure:
create procedure myproc
@list nvarchar(128)
as
...
select *
from something
where id in (@list)
Which, of course, you can’t do. In the where clause, SQL Server attempts to convert @list into an int, since it appears that I’m checking for id in a list of one int. The solution is to do something like this:
create procedure myproc
@list nvarchar(128)
as
...
select *
from something
where charindex(',' + cast(id as varchar) + ',', ',' + @list + ',') > 0)
I got that from here.
No Comments
Be the first to comment!
« No distinguished name in entry | Web Hosting Information » |
Leave a Reply