t-sql Convert comma separated string into int, without using user created function

前端 未结 3 1222
南笙
南笙 2020-12-31 05:13

I\'m passing a list of int\'s (comma separated)

ie. 1, 2, 3, 4

to my sp. But I\'m getting an error because the list is a string, and I\'m comp

3条回答
  •  情书的邮戳
    2020-12-31 05:40

    You don't want to cast that list into an int, but into a list of ints.

    There is no cast operator or function for that, but you can use dynamic SQL to get around it.

    Basically you write

    EXECUTE('SELECT * FROM tbl_Employee WHERE employeeID IN ('+@intArray+')')
    

    Be aware of SQL injection attacks though!

提交回复
热议问题