Crosstab Query in SQL Server 2000

时光怂恿深爱的人放手 提交于 2019-12-05 21:07:53

If you're sure there's at most one value for each parameter-item combination, you can use a simple group by:

select  item_id
,       max(case when parameter_id = 1 then value) Par1
,       max(case when parameter_id = 2 then value) Par2
,       max(case when parameter_id = 3 then value) Par3
from    item_paramenter
group by
        item_id

You can use min or avg instead of max: it shoulnd't matter because there's only one value for each parameter per item_id,

Without dynamic SQL, there is no way to return column names based on the description in the parameter table.

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

Thanks Dan and Andomar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!