sql server - how to convert rows to columns using sql query -
pls see below query
select d.emp_id, e.emp_name, a.proj_code, b.proj_name, a.activity_code, c.activity_name, convert(char(4), a.effort_date, 100) + convert(char(4), a.effort_date, 120) month, a.effort_hours timesheet_activity left join project_master b on a.proj_code = b.proj_code left join activity_master c on a.activity_code = c.activity_code left join timesheet d on a.timesheet_id = d.timesheet_id left join employee_master e on d.emp_id = e.emp_id b.proj_name in ('sales support') , (a.effort_date between (select convert(varchar(10), convert(date, '30-06-2014', 105), 23)) , (select convert(varchar(10), convert(date, '02-07-2014', 105), 23)))
the result this.
now want show below.
emp_id emp_name proj_code activity_code activity_name jun 2014 jul 2014 101257 chris 1001 9001 test 1.5 1
i want make months columns , show efforts hours same.
any suggestions highly appreciated
with abc ( paste query result here ) select * abc pivot (max(effort_hours) month in ([jun 2014],[jul 2014])) maxhrs
you change function max
math function want selecting condition
Comments
Post a Comment