日期:2014-05-17 浏览次数:20564 次
IF OBJECT_ID('tempdb..##dual1') IS NOT NULL
DROP TABLE ##dual1
IF OBJECT_ID('tempdb..#temp1') IS NOT NULL
DROP TABLE #temp1
DECLARE @sql2 VARCHAR(8000) ,
@sql3 VARCHAR(8000)
SELECT id = IDENTITY( INT,0,1 ),
groupid = 0 ,
值 = ',max(case Fmsize when ''' + fmsize
+ ''' then Flnums else 0 end ) [' + Fmsize + ']'
INTO #temp1
FROM ( SELECT DISTINCT
Fmsize
FROM TEST
) AS a
UPDATE #temp1
SET groupid = id / 80
--判断将前80条记录的值赋给变量0
SELECT @sql2 = '' ,
@sql3 = ''
SELECT @sql2 = @sql2 + 值
FROM #temp1
WHERE groupid = 0
--第一个变量
SELECT @sql3 = @sql3 + 值
FROM #temp1
WHERE groupid = 1
EXEC('select * into ##dual1 from (select styleid,colorid'
+@sql2+@sql3 +' from TEST group by styleid,colorid)a')
DROP TABLE #temp1