0

I have something like this:

idsList = '1,23,46,67,82'   

These are my parameters value which will be passed to my stored procedure, these are string values.

I want to use it something like this:

SELECT * 
FROM table1
WHERE id IN (id_list)
  • id is of type int

while

  • idsList is nvarchar (string)

How do I split the values of idsList and parse it to Int value then put it to my query?

Please for SQL Server only. Thanks in advance.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Let me [google](https://www.google.com/search?q=mssql+split+string&ie=utf-8&oe=utf-8&gws_rd=cr&ei=BP6DVcyEEKW7ygOFhrjgBg) it for you. Have a look at first result. – Andrey Korneyev Jun 19 '15 at 11:35
  • 2
    Depending on the client your using passing in a *table valued param* will negate the need for this entirely. – Alex K. Jun 19 '15 at 11:35
  • If you can't use a table valued parameter, and must split strings in sql server, then read [this article.](http://sqlperformance.com/2012/07/t-sql-queries/split-strings) – Zohar Peled Jun 19 '15 at 11:43
  • Similar question often asked in stackoverflow.com. ex: http://stackoverflow.com/questions/22380003/get-data-from-comma-separated-string-input I think, it will work. – Amit Jha Jun 19 '15 at 11:39

0 Answers0