Search code examples
sqlasp.netsql-serverxtrareport

How to change Row name into Column name in sql server 2008r2


I have a trouble to make an XtraCharts Line Diagram (XY Diagram) in asp.net using Stored procedure as binding.

I want to make the X value by R250, R500, R1000, R2000 rows and Y value are the data that already stored in each Row above.

I have an origin table like this:

========================================================
No | Sequence No | ItemId | R250 | R500 | R1000 | R2000
========================================================
1    001           118       23     13     14      24

I want to display it into

========================================================
No | Sequence No | ItemID | Value | NameX
========================================================
1    001            118      23     R250
1    001            118      13     R500
1    001            118      14     R1000
1    001            118      24     R2000

Is there any posible query to achieve that?? Thank you so much..


Solution

  • You can use apply isspecially for this :

    select t.No, t.[Sequence No], t.ItemID, tt.*
    from table t cross apply
         ( values ([R250], 'R250'),
                  ([R500], 'R500'),
                  ([R1000],'R1000'),
                  ([R2000],'R2000')
         ) tt (Value, NameX);