SQL Server 2000 中的交叉表查询 [英] Crosstab Query in SQL Server 2000

查看:38
本文介绍了SQL Server 2000 中的交叉表查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望之前有人尝试过,我可以在继续之前得到一些建议.

I am hoping that someone has attempted this before and I can get some advice before I go any further.

我希望在 sql-server 2000 中生成类似于交叉表查询的内容.

I am looking to produce something similar to a crosstab query in sql-server 2000.

我有一个类似于以下的表结构:

I have a table structure similar to the following:

Item       Item_Parameter      Parameter
id         item_id             id
desc       parameter_id        desc
           value

我想要做的是通过查询/存储过程将数据展平,以便更轻松地构建报告.

What I am looking to do is to flatten out the data through a query/stored procedure to make building reports easier.

理想的解决方案会产生如下结果:

The ideal solution would produce results such as:

             Parameter.desc[0]      Parameter.desc[1]      Parameter.desc[3]...
item.id[0]   Item_Parameter.value   Item_Parameter.value   Item_Parameter.value
item.id[1]   Item_Parameter.value   Item_Parameter.value   Item_Parameter.value   

推荐答案

我最终使用了存储过程 (http://www.sqlteam.com/article/dynamic-cross-tabs-pivot-tables) 动态创建 sql 语句.

I ended up using a stored procedure (http://www.sqlteam.com/article/dynamic-cross-tabs-pivot-tables) to create a sql statement dynamically.

感谢丹和安多玛

这篇关于SQL Server 2000 中的交叉表查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆