DECLARE @DATAAREAID AS NVARCHAR(MAX)
set @DATAAREAID='001,002,003,004'
if object_id('tempdb..##MyTempTable1') is not null
Begin
DROP TABLE ##MyTempTable1 --如果有存在就删除临时表
End
Select * Into ##MyTempTable1 From
(
SELECT B.id,B.typeid
FROM (
SELECT [value] = CONVERT(XML, '<v>' + REPLACE(@DATAAREAID,',', '</v><v>') + '</v>')
) A
OUTER APPLY(
SELECT id = N.v.value('.', 'nvarchar(100)'),typeid=1
FROM A.[value].nodes('/v') N(v)
) B
) as T
select PRICECALCID,Price,DATAAREAID,MisItemName into ##tmp2
from A
where DATAAREAID in (select id from ##MyTempTable1 where typeid=1)
拼接字符串转化为table并作为查询条件
最新推荐文章于 2023-11-09 10:50:51 发布