0

I have the following table structure. I want to 2 Header for Different Table columns Using Pivot. Also I have mention my expected output.

Table : 1
tblProject

ProhectId    ProjectName Intime  OutTime
934            AYX       540     1020
935            ABC       540     1020  
936            XYZ       540     1020
937            QWE       540     1020
938            RTY       480     1020

table 2

tblCode

Id     ProhectId      Code 
1        934            ABC001 
2        935            XYZ002 
3        936            255000 
4        937            789654 
5        938            458922

I Have Tried too result with

select * from (select sum((convert(decimal,OutTime - InTime))/60)  as TotalTime, ProjectName from tblProject  group BY ProjectName)
src pivot(Max(src.TotalTime) for src.ProjectName in (AYX,ABC,XYZ,QWE,RTY)) piv

I am not able to Pivot of 2nd Table with New header of Project Code.

Expected Output:

Project Name    AYX     ABC      XYZ    QWE     RTY
code            ABC001  XYZ002  255000  789654  458922
                 8(Hours)     8       8      8       9
Rama
  • 9
  • 4
  • But I Use 2 Table....and want 2 Header for Project Name and Project Code – Rama Jul 12 '18 at 09:30
  • @Ramakrishna Jadhav: First join those two tables and fetch your required output. Second You can't have multiple headers as you would in excel but you can pre-concatenate your headers instead. – Mani Deep Jul 12 '18 at 09:35
  • Please can you give me the example?? – Rama Jul 12 '18 at 09:37
  • https://stackoverflow.com/questions/42536325/tsql-pivot-with-multiple-column-headers – Mani Deep Jul 12 '18 at 09:37

0 Answers0