-2

I have a table with data like this in SQL Server:

date        batch name              id              locatio
-------------------------------------------------------------------
Jul-2010    BPRGNMCTHKDKS621010070  Kodak 42        GREATER NOIDA
Nov-2010    BPRHYMCTHHPPS607210600  HYD_HP_KV-124   HYDERABAD
Dec-2010    BPRDLMCTHHPPS613110839  Alpha 112       DELHI
Dec-2010    BPRHYMCTHHPPS607210652  HYD_HP_6J-97    HYDERABAD
Feb-2011    BPRHYMCTHHPPS607211671  HYD-HP-KV-128   HYDERABAD
Jan-2011    BTPHYMCTHHPPS607211712  HYD-HP-HPT-246  HYDERABAD

I need output like

date , batch name , id , location 1 , loct 2 , loc 3 , loc4 and so on ..

I need the counts on the base of batch name or id.

Example output:

date batch name id    delhi hyd bang etc etc
---------------------------------------------
1    gh          xyz   34   45  6
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
tarun
  • 1
  • 3
  • This example output is not helpful. Where do the column names "delhi","hyd","bang" come from? What about etc? What are the row data? – George Menoutis May 07 '19 at 07:27
  • Maybe this post could help: https://stackoverflow.com/questions/13372276/simple-way-to-transpose-columns-and-rows-in-sql Regards – AndreaM May 07 '19 at 07:34
  • i think you are expecting pivot logic.. if 34,45 these values are location values means you can go to pivot logic – Ranjith.V May 07 '19 at 08:51
  • column names "delhi","hyd","bang" come from? What about etc - from location column which is in main table . – tarun May 07 '19 at 08:51

1 Answers1

0

here is a link about a possible answer:

Simple way to transpose columns and rows in SQL?

Hope it helps

AndreaM
  • 31
  • 4