如何在Sql查询中选择字段作为列标题 [英] How I Can Get Select Field As Column Heading In Sql Query
问题描述
我想在这样的sql中获取一些报告。
i有三张桌子1.Location,2.Brands,3.Sales
位置(MasterTable)
名称说明
AAA Place AAA
BBB Place BBB
CCC Place CCC
品牌(MasterTable)>
名称描述
XYZ XYZ品牌
PQR PQR品牌
MNO MNO品牌
销售
SLID Sdate BrandName位置数量金额
1 9/21/2015 XYZ AAA 2 100
2 9/21/2015 XYZ CCC 3 100
3 9/21/2015 MNO BBB 3 100
有任何选项可以获得这样的报告,我不知道试试这个办法。
i am trying to get some report in sql like this.
i have three tables 1.Location,2.Brands,3.Sales
Location(MasterTable)
Name Description
AAA Place AAA
BBB Place BBB
CCC Place CCC
Brands(MasterTable)
Name Description
XYZ XYZ Brand
PQR PQR Brand
MNO MNO Brand
Sales
SLID Sdate BrandName Location Qty Amount
1 9/21/2015 XYZ AAA 2 100
2 9/21/2015 XYZ CCC 3 100
3 9/21/2015 MNO BBB 3 100
there is any option to get report like this , i got no idea to try this way.
Brand AAA BBB CCC
XYZ 2 3
MNO 3
请帮我解决这个问题。
please help me to solve this issue.
推荐答案
嗨tastini,
在SQL Server 2005中查看关于使用多维数据集和事件处理程序进行动态透视的文章,2008年及以上 [ ^ ]
Hi tastini,
see my article about Dynamic Pivoting with Cubes and eventhandlers in SQL Server 2005, 2008 and UP[^]
这篇关于如何在Sql查询中选择字段作为列标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!