Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends ,
i want to display data like this for employee salary.
if i search data between nov2012 to feb 2013

name      nov2012    dec2012     jan2013
pawan     31110      22020         2000
pawan     31110      22020         2000
pawan     31110      22020         2000
pawan     31110      22020         2000


this is my query

Select  id,name,fathername,cdepartment, [Jan],[Feb],[Mar],[Apr],[May],[Jun],[Jul],[Aug],[Sep],[Oct],[Nov],[Dec]
From
(
    Select e.cemployeecode as id,e.cfirstname+space(1)+e.clastname as name,e.cfatherfirstname+space(1)+e.cfatherlastname as fathername,    

    CAST(DateName(MONTH,cast(cast (i.lmonthid as varchar(200))+'/01/'+cast(i.lyearid as varchar(200)) as datetime)) as varchar(3))
     as Mon, round(i.HWF,2) as HWF,ed.cdepartment
        From invoice i inner join employee e on e.cemployeecode=i.cemployeeid
        inner join employeedepartment ed on ed.ldepartmentid=e.ldepartmentid
        
          where i.lyearid=@yearid and i.lcompanyid =@companyid

) as SourceTable

PIVOT
(
    Sum(HWF)
    For Mon in ( [Jan],[Feb],[Mar],[Apr],[May],[Jun],[Jul],[Aug],[Sep],[Oct],[Nov],[Dec] )
) as PivotTable


Plz help me rectifying it according to my requirement.
Posted
Updated 7-Nov-13 21:22pm
v2

Hi,

Please refer below Link it will help you in your solution (Salary using PIVOT)

http://indiandotnet.wordpress.com/2009/03/12/pivot-in-sql-server/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900