February 26, 2016 at 11:27 am
How would I pivot this query I need uompschedulenumber to be the ROW, QTY to be the summary data and redtagcode to be the columns([MIL],[CON] ,[DAM],[FIN],[NON] ,[CLM],[REP],[RRT],[SHT])
select uompScheduleNumber,
case
when redtagcode ='' then 'NON' else redtagcode end as code
,count(*) as qty
from wip_master where redtag='Y' and createdate >=DATEADD(month, DATEDIFF(month, 0, getdate() ), 0)
group by uompScheduleNumber,redtagcode
ORDER BY uompScheduleNumber,redtagcode
I add and attachment with sample data
February 26, 2016 at 12:11 pm
Please post a CREATE TABLE statement for the table, post a few handful rows of sample data as INSERT statements, and post the exact results you want returned from that data.
February 29, 2016 at 12:53 am
Hi,
This query may be helpfull
select * from
(
select * from wip_master
) p
pivot
(
sum(qty) for code in ([CLM],[CON],[DAM],[FIN],[MIL],[NON],[REP],[RRT],[SHT])
) as result
--chalam
February 29, 2016 at 7:05 am
That worked I was able to add my where clause to it and get what I need thanks
select * from
(
select uompScheduleNumber, case
when redtagcode ='' then 'NON' else redtagcode end as code
,count(*) as qty from wip_master where redtag='Y' and createdate >='02-23-2016' group by uompScheduleNumber,redtagcode
) p
pivot
(
sum(qty) for code in ([CLM],[CON],[DAM],[FIN],[MIL],[NON],[REP],[RRT],[SHT])
) as result
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply