June 20, 2014 at 1:37 am
Hi all,
How can I input parameter for Store Procedure like In ('Value1','Value2')
Example :
Create procedure GetUsers
@Users nvarchar(200)
as
Select * from Users where UserID in (@Users)
Many thanks,
Cuong:-)
June 20, 2014 at 1:40 am
You will have to split the values coming in from the parameters.
--------------------------------------------------------------------------------------------------
I am just an another naive wannabe DBA trying to learn SQL Server
June 20, 2014 at 2:05 am
Hi,
I can use dynamic TSQL, but with complex TSQL in procedure difficult to handle.
Thanks,
Cuong
June 20, 2014 at 3:30 am
No need for dynamic sql.Just split the values ('Value1','Value2') and insert into a temp table
Value1
Value2
then Select * from YourTable where Id in (Select Id from Temp)
--------------------------------------------------------------------------------------------------
I am just an another naive wannabe DBA trying to learn SQL Server
June 20, 2014 at 10:44 am
Or you could avoid the need for a table if you're using them just once.
Select *
from YourTable
WHERE Id in (Select Id from dbo.DelimitedSplit8K(@Parameter, ','))
Notice that I used the DelimitedSplit8K which you can find in here: http://www.sqlservercentral.com/articles/Tally+Table/72993/
June 20, 2014 at 8:39 pm
Hi Luis C and Sachin,
I done, thanks both of you so much.
Regards,
Cuong:-)
June 22, 2014 at 10:23 am
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply