开发者

SSRS Select Values From Rows as Fields

开发者 https://www.devze.com 2023-01-18 11:54 出处:网络
I have a table that has two columns, ID and Value.For this example l开发者_运维技巧ets say there are three rows:

I have a table that has two columns, ID and Value. For this example l开发者_运维技巧ets say there are three rows:

ID Value

A 1

B 2

C 3

The number of rows will remain constant, so I can create a field for each item I want to display, e.g. ItemAID, ItemBID, ItemCID, ItemAValue, ItemBValue, ItemCValue, however I don't know if that would be the best solution as it would require multiple select statements which SSRS doesn't seem to like.

What would be the best way of going about this, using multiple fields, writing a more elegant query or otherwise?


Check out the the up-voted answer here. You can use FORM XML and PATH:

How to use GROUP BY to concatenate strings in SQL Server?


Found it.

Using:

 SELECT a.ID AS ItemAID, b.ID AS ItemBID FROM TestTable a, TestTable b WHERE a.ID='A' and b.ID = 'B'  

worked out to get me what I needed.


It sounds as though you are trying to pivot data - a Tablix (ie. a Matrix table) would be an SSRS-based solution to this issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消