Why null is coming

  • create table #tmp (name varchar(50), dates varchar(50), rvalue varchar(50))

    Insert into #Tmp

    Select 'ttesttt','20 Apr 2010','Rou'

    union Select 'ttesttt','23 Apr 2010','AA'

    union Select 'ttesttt','21 Apr 2010','ereg'

    union Select 'ttesttt','22 Apr 2010','ereg'

    --- Select * from #Tmp

    SELECT name, [20 Apr 2010],[23 Apr 2010],[21 Apr 2010],[22 Apr 2010]

    FROM

    (SELECT t2.name

    , t1.rvalue

    FROM #Tmp AS t1

    JOIN #Tmp AS t2 ON t1.name = t2.name and t1.dates=t2.dates) p

    PIVOT

    (

    MAX(rvalue)

    FOR rvalue IN

    ( [20 Apr 2010],[23 Apr 2010],[21 Apr 2010],[22 Apr 2010] )

    ) AS pvt

    ORDER BY name;

    Why null is coming correct me...

    Thanks

    Thanks
    Parthi

  • Hi Parthi,

    You have give it as

    MAX(rvalue)

    FOR rvalue IN( [20 Apr 2010],[23 Apr 2010],[21 Apr 2010],[22 Apr 2010] )

    the values are from dates table but you have given rvalue. It should be

    MAX(dates)

    FOR dates IN

    ( [20 Apr 2010],[23 Apr 2010],[21 Apr 2010],[22 Apr 2010] )

    Thanks & Regards,
    MC

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply