Pivot Issue

  • Hi

    I have below pivot& i want to display data like below

     

    20              100                Sudhir Kumar             30 Days            Davinder        1 Day & so on

    SELECT * FROM

    (

    SELECT

    (Min(L.[EntryCode])) AS [PR Number]

    --,L.[RequestDate] [Entry Date]

    --,L.[ApprovalDate] [Completion Date]

    ,(select top 1 DATEDIFF(d,Min([RequestDate]),Max([ApprovalDate])) FROM [View_Capex_StepWiseApprovalDetail] where EntryCode=L.EntryCode) as [Total Days]

    --,DATEDIFF(d,[RequestDate],[ApprovalDate]) as [DaysToApprove]

    ,[EmpName]+' - '+CAST(DATEDIFF(d,[RequestDate],[ApprovalDate]) as Varchar(50)) + (CASE WHEN DATEDIFF(d,[RequestDate],[ApprovalDate]) <= 1 THEN ' Day' ELSE ' Days' END) AS [DaysToApprove]

    ,LevelName

    FROM [View_Capex_StepWiseApprovalDetail] L

    where l.EntryCode = 209

    group by l.entrycode,l.levelname,l.RequestDate,l.ApprovalDate,EmpName

    ) t

    PIVOT(

    MIN([DaysToApprove])

    FOR [LevelName] IN ([Level 1], [Level 2], [Level 3], [Level 4], [Level 5], [Level 6], [Level 7], [Level 8], [Level 9], [Level 10], [Level 11], [Level 12])

    ) AS pivot_table1

    GO

    Thanks

  • Ok... this is the 3rd post on the same subject.  One of your others provided some output, one of the others provided some input, and this one provides the code you used that apparently didn't work.  My recommendation is that you edit this one with all the information on a single post.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I cant even make sense of what the data is supposed to render to. I cant make out any columns in the desired output. Please put in time to present your situation in a tidy manner if we are to put in time to help you.

    Jeff's links in his signature should give you all you need to get started.

    ----------------------------------------------------

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

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