declare @t table ( QuoteRef int, ProductA int, ProductB i...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

declare @t table
(
    QuoteRef int,
    ProductA int,
    ProductB int,
    ProductC int,
    ProductD int
);

INSERT INTO @t VALUES(12, 222333, 474884, 0, 0);


;WITH data as
(
SELECT [QUOTERef], [ProductLine], [Value]

FROM 
   (
    SELECT [QUOTERef], [ProductA], [ProductB], [ProductC], [ProductD]

FROM @t) p
UNPIVOT
   ([Value] FOR [ProductLine] 
   IN ([ProductA], [ProductB], [ProductC], [ProductD] )
)AS unpvt
) 
SELECT * FROM DATA WHERE Value <> 0

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results
:records returned in :time ms:cached