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

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


    And the resulting table looks like this

    [​IMG]

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

    7/2---7/1---6/30--6/29

    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