I have table on my SQL database
Code | Ordered | Cut01 | Cut02 | Cut03 | Confirmed
--------------------------------------------------
8832 10 1 1 3 5
8821 12 0 1 2 9
8122 20 10 0 0 10
8901 11 0 8 1 2
How can I separate rows for each Code
, which have several Cuts*
that is <> 0
and multiply themselves like:
Code | Ordered | Cut01 | Cut02 | Cut03 | Confirmed
--------------------------------------------------
8832 1 1 0 0 0
8832 1 0 1 0 0
8832 8 0 0 3 5
--------------------------------------------------
8821 1 0 1 0 0
8821 11 0 0 2 9
--------------------------------------------------
8122 20 10 0 0 10
--------------------------------------------------
8901 8 0 8 0 0
8901 3 0 0 1 2
Confirmed = Ordered - Cut01 - Cut02 - Cut03
As you can see in result table Sum of Ordered
for each code = Ordered for this code from first table, also it works for Sum of Confirmed
.
But in each of row I have only single Cut
that is not equal to 0.
How can I do it by using T-SQL?