select top 5 expe.HeatingTime as 升温时间, expe.HoldingTime as 保温时间
from ExperimentalProcessSteps as expe
left join ProductFamily as pf on expe.ProductFamilyId = pf.ProductFamilyId
CREATE TABLE #YS--元素
( ID INT IDENTITY,
Item0 NVARCHAR(20),
Item1 NVARCHAR(20),
Item2 NVARCHAR(20),
Item3 NVARCHAR(20),
Item4 NVARCHAR(20),
Item5 NVARCHAR(20)
)
---新增四行
INSERT #YS (Item0)
SELECT '升温时间'
INSERT #YS (Item0)
SELECT '保温时间'
/* 游标循环给YS值 */
DECLARE @ItemName1 NVARCHAR(20),@ItemName2 NVARCHAR(20)
DECLARE @RowNum INT=1,@ItemNum INT=1 --行数,项目数
DECLARE @Sql NVARCHAR(500)='' --存放修改#YS的sql语句
--查询转换前
DECLARE cursor_YS CURSOR FAST_FORWARD READ_ONLY FOR
select top 5 expe.HeatingTime, expe.HoldingTime
from ExperimentalProcessSteps as expe
left join ProductFamily as pf on expe.ProductFamilyId = pf.ProductFamilyId
OPEN cursor_YS
FETCH NEXT FROM cursor_YS
INTO @ItemName1,@ItemName2
WHILE @@FETCH_STATUS = 0
BEGIN
SET @Sql=' UPDATE #YS SET Item'+LTRIM(@RowNum)+'='''+@ItemName1+''' WHERE ID=1
UPDATE #YS SET Item'+LTRIM(@RowNum)+'='''+@ItemName2+''' WHERE ID=2'
EXEC (@Sql)
SET @RowNum=@RowNum+1
FETCH NEXT FROM cursor_YS
INTO @ItemName1,@ItemName2
END
CLOSE cursor_YS
DEALLOCATE cursor_YS
--查询转换后
SELECT Item0,Item1,Item2,Item3,Item4,Item5 FROM #YS
drop table #YS