C# 如何更新unpivot query my query attached Sql Server中的列?

C# 如何更新unpivot query my query attached Sql Server中的列?,c#,asp.net,sql-server,sql-server-2008,unpivot,C#,Asp.net,Sql Server,Sql Server 2008,Unpivot,我试图在我的查询中添加列,如下所示 SELECT Name as [holiday_name] FROM tableMonth t UNPIVOT (ID for Name in (m1,m2,m3,sf1,sf2)) u WHERE ID != 0.0 and D_No ='0700' 这个查询运行得很好,但是当我添加“sf1”和“sf2”时,它给了我一个错误 "The type of column "sf1" conflicts with the type of other columns

我试图在我的查询中添加列,如下所示

SELECT Name as [holiday_name] FROM tableMonth t UNPIVOT (ID for Name in (m1,m2,m3,sf1,sf2)) u WHERE ID != 0.0 and D_No ='0700'
这个查询运行得很好,但是当我添加“sf1”和“sf2”时,它给了我一个错误

"The type of column "sf1" conflicts with the type of other columns specified in the UNPIVOT list."
我如何使用我想更新的列(如“sf1”和“sf2”)运行上面提到的查询

希望能给你一些建议

谢谢

在取消PIVOT期间创建新列的一种方法
我相信这是你的要求。

用varchar(255)对该列进行转换我不明白你的答案?从表t UNPIVOT中选择名称[holiday_Name]。(m1,m2,m3,cast(sf1作为十进制(18,16))作为sf1,cast(sf2作为十进制(18,16))作为sf2)u,其中ID!=0.0和D_No='0700'@mohan现在应该如上所述了吗?
CREATE TABLE pvt (VendorID int, Emp1 int, Emp2 int,
    Emp3 int, Emp4 int, Emp5 int);
GO
INSERT INTO pvt VALUES (1,4,3,5,4,4);
INSERT INTO pvt VALUES (2,4,1,5,5,5);
INSERT INTO pvt VALUES (3,4,3,5,4,4);
INSERT INTO pvt VALUES (4,4,2,5,5,4);
INSERT INTO pvt VALUES (5,5,1,5,5,5);
GO


    SELECT VendorID, newcolumn, Orders,
case when len(VendorID) > 1 then ' ' end newcolumn1 ,
case when len(VendorID) > 1 then ' ' end newcolumn2 
    FROM 
   (SELECT VendorID, emp1,emp2,emp3,emp4,emp5
   FROM pvt) p
UNPIVOT
   (Orders FOR newcolumn IN (emp1,emp2,emp3,emp4,emp5)
)AS unpvt;