Convert row to columns in SQL Server -


i have query returns results this:

location id location code   location name   division code   ssourcecode division name   business unit code  business unit name 83806   d4009   vanier mitsubishi fuso  sales_01    sales_01    sales_01    sales department    fuso vehicle sales department 83806   d4009   vanier mitsubishi fuso  parts_a0    parts_a0    parts district a0   parts department    fuso parts department 83806   d4009   vanier mitsubishi fuso  service_c1  service_c1  service division c1 service department  fuso service department 

i want have results this:

location id    location code    location name   parts division code   parts ssourcecode  parts division name    sales division code   sales division name       sales business unit code    sales business unit name    parts business unit code    parts business unit name 

so each locationid need 1 row, respective parts/service/sales division/business unit codes , names showing on same row separate columns....not convinced can pivoting, if possible can point me in right direction or give me examples of how can achieved.

without pivoting need inner join table self many times, although data posted looks number of rows (parts) not static, make pivoting again.

what suggest split operation two, first statement select rows converted columns (with id linking later):

id  parts ssourcecode   parts division name     sales division code    sales division name        sales business unit code     sales business unit name  

and use pivoting on data, inner join data same table again

select distinct location id location code   location name   division code table inner join previousdata 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -