Link to home
Start Free TrialLog in
Avatar of AbeSpain
AbeSpainFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Passing the value for an IN clause to a stored procedure

I have the list of elements seperated by commas that I am passing to a stored procedure that I want to pass in to an 'In' clause for the where statement. I have done this by hand before ' Where clientsid In (7,8,9)' etc but am stuck at trying to do this dynamically. I can pass the elements over in a string, say '7,8,9', but then I need to convert this to an integer. Is it possible to pass over the contents of an In clause dynamically? I
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
note:
the EXEC() method of doing looks simpler, BUT has some side effects you should be aware of:
* permissions to the tables used will need to be granted to the caller of the procedure and not the owner of the procedure
* the execution plan might not be the same one
Avatar of AbeSpain

ASKER

2 solutions in one! Angellllllllll's works very well and is more what I am looking for due to it not using dynamic sql. I have split the points across the two answers weighted on the one more useful to me.