在SQL Server中将列转换为行 [英] converting columns into rows in in sql server
问题描述
大家好,
请问有人可以建议我如何将这些列转换为临时寓言的行吗?.
Hi every one,
Can any one please suggest me how to convert the columns into rows of a temporary rable..?
select convert( varchar(50), NewDate, 103 ) as 'NewDate',AuditTotal AS 'Total Audited' FROM @Months
--------
输出:
NewDate经审核的总数
2011年8月1日0
2011年8月2日1
2011/08/03 2
-----------------
但是,我希望结果显示为:
NewDate 08/01/2011 08/02/2011 08/03/2011
审核总数0 1 2
请任何人以支点或其他方式建议我..
问候,
--------
OUTPUT:
NewDate Total Audited
08/01/2011 0
08/02/2011 1
08/03/2011 2
-----------------
But, I want to the result to be displayed as:
NewDate 08/01/2011 08/02/2011 08/03/2011
Total Audited 0 1 2
Please any one suggest me with pivot or some other idea..
Regards,
推荐答案
在SQLServer中,有一个叫做 ^ ]旨在完成您想做的事情.
我尚未阅读您所有存储的proc(相当多的阅读),因此不知道它是否适合您的情况.
仍然,请阅读并查看它是否有用.
In SQLServer there is a thing called a Pivot Table[^] which is designed to do what you are trying to do.
I have not read all of your stored proc (rather a lot to read) and so do not know if it will fit your scenario.
Still, have a read and see if it is of use.
您好,
您是否要转换来自查询的行:
Hi,
Do you mean to convert the rows coming from the query:
select convert( varchar(50), NewDate, 103 ) as ''NewDate'',AuditTotal AS ''Total Audited'' FROM @Months
在这种情况下,只要数据类型匹配,就可以使用UNION,例如:
If that''s the case, you could use UNION as long as the datatypes match, something like:
select convert( varchar(50), NewDate, 103 ) as ''NewDate'' FROM @Months
UNION ALL
select AuditTotal AS ''Total Audited'' FROM @Months
坦率地说,这没有任何意义,所以也许我误解了您的问题.
But frankly this doesn''t make sense so perhaps I misunderstood your question.
这篇关于在SQL Server中将列转换为行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!