Pivot Issue

  • Hi

    Below is the query . I want to display data in 1 row .In below code there are 12 levels , i want data in 1 rows.

    Hi Amit

    Below is the query . I want to display data in 1 row .In below code there are 12 levels , i want data in 1 rows.

    I am following this link - https://www.datameer.com/blog/sql_how-to-use-pivot-to-convert-rows-to-columns-in-sql-server-db/

    Hi Amit

    If i comment below lines then it is working fine , but i want to add these columns also.

    --,L.[LogDetail] [Status]
    --,L.[RequestDate] [Entry Date]
    --,L.[ApprovalDate] [Completion Date]
    --,DATEDIFF(d,L.[RequestDate],L.[ApprovalDate]) as [Total Days]



    PR NumberStatusEntry DateCompletion DateTotal DaysDaysToApproveLevelName
    209PR Request Approved2020-04-07 12:57:32.8332020-05-07 12:44:43.3073030Level 1
    209PR Request Approved2020-05-07 12:44:43.3072020-05-08 16:21:39.32711Level 2
    209PR Request Approved2020-05-08 16:21:39.3272020-05-18 17:53:29.7931010Level 3
    209PR Request Approved2020-05-18 17:53:29.7932020-06-26 10:56:05.8473939Level 4
    209PR Request Approved2020-06-26 10:56:05.8472020-07-07 09:05:04.5031111Level 5
    209PR Request Approved2020-07-07 09:05:04.5032020-07-07 09:05:36.57700Level 6
    209PR Request Approved2020-07-07 09:05:36.5772020-07-07 12:18:20.12700Level 7
    209PR Request Approved2020-07-07 12:18:20.1272020-07-08 16:24:42.72311Level 8
    209PR Request Approved2020-07-08 16:24:42.7232020-07-08 16:26:17.62000Level 9
    209PR Request Approved2020-07-08 16:26:17.6202020-07-10 09:31:18.31022Level 10
    209SAP PR Number Updated2020-07-10 09:31:18.3102020-07-10 10:56:16.06000Level 11
    209PR Request Approved2020-07-10 10:56:16.0602020-07-16 12:03:01.05366Level 12
    Thanks

     

    Thanks

  • Thanks for posting your issue and hopefully someone will answer soon.

    This is an automated bump to increase visibility of your question.

  • This was removed by the editor as SPAM

  • You'll find that very few people are going to go read the article you provided a link to.  You also haven't posted the full code you're using .  You've also not posted the expected "1 row" result that you're looking for so folks don't have to guess what that actually means.

    --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)

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

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