TSQL varchar string manipulation

后端 未结 5 1182
失恋的感觉
失恋的感觉 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条回答
  •  情话喂你
    2021-01-14 23:21

    I ended up doing something very similar that I thought I'd post. (I'll give credit to Mitch however)

    This takes care of the middle:

    SET @StateList = REPLACE(@StateList, ',', ''',''')

    Then quote the edges:

    SET @WhereClause1 = @WhereClause1 + 'AND customerState IN (''' + @StateList + ''') '

提交回复
热议问题