PIVOT not performing as expected.

Posted by Matt W on Stack Overflow See other posts from Stack Overflow or by Matt W
Published on 2010-05-28T10:38:05Z Indexed on 2010/05/28 10:42 UTC
Read the original article Hit count: 264

Filed under:
|
|

Sorry for an unclear question previously; hopefully I can start again...

I have this data:

entityid    name                 stringvalue
----------- -------------------- --------------------
1           ShortDescription     Coal
1           LongDescription      BlackCoal
1           ShortDescription     Gold
1           LongDescription      WhiteGold
1           ShortDescription     Steel
1           LongDescription      StainlessSteel

And this query:

select *
from
(
    select entityid, name, stringvalue as stringvalue
    from mytable
) as d
pivot
(
    min([stringvalue])
    for [name] in ([ShortDescription],[LongDescription])
)
as p

Producing this output:

entityid ShortDescription LongDescription
-------- ---------------- ---------------
1        Coal             BlackCoal

Could someone tell me why the other rows are not being produced, please? I was expecting to see:

entityid ShortDescription LongDescription
-------- ---------------- ---------------
1        Coal             BlackCoal
1        Gold             WhiteGold
1        Steel            StainlessSteel

Thanks,

Matt

© Stack Overflow or respective owner

Related posts about sql

Related posts about pivot