TSQL varchar string manipulation

后端 未结 5 1234
失恋的感觉
失恋的感觉 2021-01-14 22:36

I have a variable which contains the following string: AL,CA,TN,VA,NY

I have no control over what I get in that variable (comes from reporting services)

I

5条回答
  •  猫巷女王i
    2021-01-14 23:17

    Don't bother with dynamic sql.

    You need to convert the string to a table so A,B,C,D

    becomes

    Value A B C D

    using a function like http://www.sqlusa.com/bestpractices/training/scripts/splitcommadelimited/

    then you can use CROSS APPLY (which is like joining to a table, but a table created by a function) or you can just put it in a table variable and join to that

提交回复
热议问题