부분합 Rollup

DBTool/MSSQL 2012. 4. 18. 11:05

CREATE TABLE dbo.GroupingNULLS (
    Store nvarchar(19)
    ,SaleYear nvarchar(4)
    ,SaleMonth nvarchar (7)
    ,SalePrice int
    ,NonePrice int
)

INSERT INTO dbo.GroupingNULLS VALUES
(NULL,NULL,'January',0,0)
,(NULL,'2002',NULL,0,0)
,(NULL,NULL,NULL,0,0)
,('Active Cycling',NULL ,'January',0,0)
,('Active Cycling','2002',NULL,4,0)
,('Active Cycling',NULL ,NULL,0,2)
,('Active Cycling',NULL,'January',1,0)
,('Active Cycling','2003','Febuary',0,0)
,('Active Cycling','2003',NULL,0,4)
,('Mountain Bike Store','2002','January',0,0)
,('Mountain Bike Store','2002',NULL,4,0)
,('Mountain Bike Store',NULL,NULL,0,0)
,('Mountain Bike Store','2003','January',0,0)
,('Mountain Bike Store','2003','Febuary',0,3)
,('Mountain Bike Store','2003','March',10,0);

SELECT ISNULL(Store,
    CASE WHEN GROUPING(Store) = 0 THEN 'UNKNOWN' ELSE 'ALL' END)
    AS Store
    ,ISNULL(CAST(SaleYear AS nvarchar(7)),
    CASE WHEN GROUPING(SaleYear)= 0 THEN 'UNKNOWN' ELSE 'ALL' END)
    AS SalesYear
    ,ISNULL(SaleMonth,
    CASE WHEN GROUPING(SaleMonth) = 0 THEN 'UNKNOWN' ELSE 'ALL'END)
    AS SalesMonth
    ,sum(SalePrice) AS DcCount
    ,SUM(nonePrice) as Count
FROM dbo.GroupingNULLS
GROUP BY ROLLUP(Store, SaleYear, SaleMonth);

부분합 Rollup 예제 참조.

Posted by 말없제이
,

SQL2008에서 저장프로시저가 안보일때...
"F7" 눌러 탐색기 정보에서 봐야 함.
Posted by 말없제이
,
MSSQL 2008 접속정보 저장내역 삭제
C:\Users\계정\AppData\Roaming\Microsoft SQL Server\100\Tools\Shell\SqlStudio.bin 삭제
참조자료 :
http://blog.naver.com/PostView.nhn?blogId=mad_darksun&logNo=60130704542&redirect=Dlog&widgetTypeCall=true
Posted by 말없제이
,
LEN()은 Text 대용량에서 에러가능성.

DATALENGTH() 사용 적용가능
Posted by 말없제이
,