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)