DROP TABLE VENKAT_SAMPLE
CREATE TABLE VENKAT_SAMPLE(PART1 VARCHAR(100),PART2 VARCHAR(100),
PART3 VARCHAR(100),PART4 VARCHAR(100),PART5 VARCHAR(100),[DATE] DATETIME)
INSERT INTO VENKAT_SAMPLE VALUES('XYZ','ABC','PQR','EFG','PQR','11/04/2010')
INSERT INTO VENKAT_SAMPLE VALUES('','XYZ','PQR','ABC','','12/04/2010')
INSERT INTO VENKAT_SAMPLE VALUES('ABC','PQR','','XYZ','EFG','4/13/2010')
INSERT INTO VENKAT_SAMPLE VALUES('ABC','PQR','','XYZ','EFG','4/14/2010')
SELECT * FROM VENKAT_SAMPLE;
WITH VENKAT_CTE AS
(
SELECT [DATE], PART,Orders
FROM
(SELECT [DATE], PART1,PART2,PART3,PART4,PART5
FROM VENKAT_SAMPLE ) p
UNPIVOT
(Orders FOR PART IN
(PART1,PART2,PART3,PART4,PART5)
)AS unpvt
)
SELECT COUNT(1) AS COUNT,ORDERS FROM VENKAT_CTE
WHERE [DATE] >= '6/14/2010' GROUP BY ORDERS
No comments:
Post a Comment