Everybody,
I have the following Code that work fine.
What I want to do is when s.Week = 0, then do not place the week statement.
DECLARE @SQLString VarChar(8000)
SELECT @SQLString =
ISNULL(@SQLString + ',', '') + CHAR(13) +
'SUM(CASE ' +
'WHEN Data.Year = ' + CAST(s.Year as VarChar(4)) +
' AND Data.Month = ' + CAST(s.Month as VarChar(2)) +
' AND Data.Week = ' + CAST(s.Week as VarChar(2)) +
' THEN Data.Qty ELSE 0 END)
FROM
(
SELECT TOP 100 PERCENT
dbo.BD.Year,
dbo.BD.Month,
dbo.BD.Week
FROM dbo.BD
) s
I have the following Code that work fine.
What I want to do is when s.Week = 0, then do not place the week statement.
DECLARE @SQLString VarChar(8000)
SELECT @SQLString =
ISNULL(@SQLString + ',', '') + CHAR(13) +
'SUM(CASE ' +
'WHEN Data.Year = ' + CAST(s.Year as VarChar(4)) +
' AND Data.Month = ' + CAST(s.Month as VarChar(2)) +
' AND Data.Week = ' + CAST(s.Week as VarChar(2)) +
' THEN Data.Qty ELSE 0 END)
FROM
(
SELECT TOP 100 PERCENT
dbo.BD.Year,
dbo.BD.Month,
dbo.BD.Week
FROM dbo.BD
) s