1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to pivot this table based on the date? - SQL SSRS

Discussão em 'Outras Linguagens' iniciado por Stack, Julho 8, 2021.

  1. Stack

    Stack Membro Participativo

    I have this simple query

    Clients.Name ClientName,
    count(PickTickets.Id) Count,
    (str(ltrim(DATEPART(month, PickTickets.CloseDate))) + '/' + str(ltrim(DATEPART(day, PickTickets.CloseDate))) ) Day
    join Customers on Customers.Id = PickTickets.CustomerId
    join Clients on Clients.Id = PickTickets.ClientId
    join Warehouses on Warehouses.Id = PickTickets.WarehouseId
    PickTickets.CloseDate is not null
    group by
    (str(ltrim(DATEPART(month, PickTickets.CloseDate))) + '/' + str(ltrim(DATEPART(day, PickTickets.CloseDate))) )
    order by CustomerCode, Day desc

    And the resulting table looks like this


    Is it possible to pivot this table, so on top are all the dates like


    And then under them its the Customer plus the amount of orders.

    I'm not really sure how to start this, or if it's even possible, since there are two columns I want to display, Customer and Count. Would we have to combine it into one column by turning it into a string like I did with the date?

    Any help would be greatly appreciated.

    Continue reading...

Compartilhe esta Página

Para os pais de Plantão algumas dicas