I have a stored procedure that is receiving as a parameter a list of values to include in a query. For example NY, NJ, CT, PA
In my dynamic SQL query in the stored procedure, I want to select records
WHERE state IN ('NY', 'NJ', 'CT', 'PA').
If I use the parameter as it gets to the SP, I would be doing
WHERE state IN 'NY, NJ, CT, PA'.
Therefore, I need to convert
'NY, NJ, CT, PA'
to
('NY','NJ','CT','PA').
Is there a function to do that?
Thanks!
Hey, I think Kevin pointed in the right direction here. All I need to do is:
WHERE state IN REPLACE(('NY, NJ, CT, PA'), ',' , ''',''')
Or, since I really have it in a variable...
WHERE state IN REPLACE ((@StateList), ',' , ''',''')