Other solution instead of Cursoring

Posted by dewacorp.alliances on Stack Overflow See other posts from Stack Overflow or by dewacorp.alliances
Published on 2010-05-28T00:17:58Z Indexed on 2010/05/28 0:21 UTC
Read the original article Hit count: 546

Filed under:
|

Hi there

I have the following pivoting table that I manage to do and here's the result and I want to put a bit further.

**NTRITCode; NTRIId; Parameter; Usage; Rate**

CURRENT; 4; Peak; 100; 0.1
CURRENT; 4; NonPeak; 200; 0.2

PROPOSED; 6; Peak; 100; 0.2
PROPOSED; 6; NonPeak; 200; 0.3

PROPOSED; 8; Peak; 200; 0.3
PROPOSED; 8; NonPeak; 200; 0.5

As you can see there is 2 sets of proposed (ID=6 and 8). I want somehow display like this below so each set has a pair of CURRENT as well as the PROPOSED one as follow:

**Sequence; NTRITCode; NTRIId; Parameter; Usage; Rate**

1; CURRENT; 4; Peak; 100; 0.1
1; CURRENT; 4; NonPeak; 200; 0.2
1; PROPOSED; 6; Peak; 100; 0.2
1; PROPOSED; 6; NonPeak; 200; 0.3

2; CURRENT; 4; Peak; 100; 0.1
2; CURRENT; 4; NonPeak; 200; 0.2
2; PROPOSED; 8; Peak; 200; 0.3
2; PROPOSED; 8; NonPeak; 200; 0.5 

Again all I can think off is using combination of CURSOR and UNION but is there any TSQL that can do this?

Thanks

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server-2005