I have the following pivoting table that I manage to do and here's the result and I want to put a bit further.
RID; 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
1; PROPOSED; 8; Peak; 200; 0.3
1; 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; RID; NTRITCode; NTRIId; Parameter; Usage; Rate**
1; 1; CURRENT; 4; Peak; 100; 0.1
1; 1; CURRENT; 4; NonPeak; 200; 0.2
1; 1; PROPOSED; 6; Peak; 100; 0.2
1; 1; PROPOSED; 6; NonPeak; 200; 0.3
2; 1; CURRENT; 4; Peak; 100; 0.1
2; 1; CURRENT; 4; NonPeak; 200; 0.2
2; 1; PROPOSED; 8; Peak; 200; 0.3
2; 1; 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
I'm not sure you really need a recursive query as much as a Numbers/Tally table in order to get the equivalent sequence numbers for the "CURRENT" values as those of the "PROPOSED" values.
perhaps what mdma posted on this question may work for you. i have never thought of it but a recursive CTE is very interesting. The starting point could be number of distinct 'proposed pairs' and then it would union with itself as many times as necessary to create the right number of 'current pairs'
SQL: how to get all the distinct characters in a column, across all rows