以下代码拆分“XX,XX,XX”这样的字符串,拆分结果可用于Where条件
DECLARE @strID VARCHAR(200) = '1,2,3'; DECLARE @xml XML; SELECT @xml = CONVERT(XML, '<root><place><id>' + REPLACE(@strID, ',', '</id></place><place><id>') + '</id></place></root>'); IF OBJECT_ID('tempdb..#Temp') IS NOT NULL BEGIN DROP TABLE #Temp; END; SELECT T.C.value('id[1]', 'varchar(36)') AS ID INTO #Temp FROM @xml.nodes('/root/place') AS T(C); SELECT ID FROM #Temp;