January 27, 2010 at 6:41 am
Hi
Please tell me what is wrong with this syntax:
Declare
@EndPeriod Numeric,
@Consolidate Varchar(200) = Null,
@Level3 Varchar(200) = Null,
@Division Varchar(200) = Null
Set @EndPeriod = 200912
Set @Consolidate = '(Retail Consolidate)'
Set @Level3 = '(LEVEL3)'
--Set @Division is null
Begin
IF @Consolidate = '(Retail Consolidate)'
SELECT Consolidate as DisplayLevel , COUNT([HC CAT1]) AS cntStaffNO, [HC CAT1], [HC Cat5], [HC CAT6]
FROM HRC_MIS
WHERE (Period = @EndPeriod)
AND (Consolidate IN(Select * From dbo.Split(@Consolidate, ',')) OR (@Consolidate = '(Retail Consolidate)'))
GROUP BY Consolidate, Level3, [HC CAT1], [HC Cat5], [HC CAT6]
ORDER BY [HC CAT1]
Else
SELECT Level3 as DisplayLevel, COUNT([HC CAT1]) AS cntStaffNO, [HC CAT1], [HC Cat5], [HC CAT6]
FROM HRC_MIS
WHERE (Period = @EndPeriod)
AND Consolidate = @Consolidate
AND (Level3 IN (Select * From dbo.Split(@Level3, ',')))
GROUP BY Level3, [HC CAT1], [HC Cat5], [HC CAT6]
ORDER BY Level3
IF @Level3 <> '(LEVEL3)'
SELECT Division as DisplayLevel, COUNT([HC CAT1]) AS cntStaffNO, [HC CAT1], [HC Cat5], [HC CAT6]
FROM HRC_MIS
WHERE (Period = @EndPeriod)
AND Level3 IN (Select * From dbo.Split(@Level3, ','))
GROUP BY Division, [HC CAT1], [HC Cat5], [HC CAT6]
ORDER BY Division
End
January 27, 2010 at 6:51 am
It's Ok I fixed it
Declare
@EndPeriod Numeric,
@Consolidate Varchar(200),
@Level3 Varchar(200),
@Division Varchar(200)
Set @EndPeriod = 200912
Set @Consolidate = '(Retail Consolidate)'
Set @Level3 = '(LEVEL3)'
--Set @Division is null
IF @Consolidate = '(Retail Consolidate)'
Begin
SELECT Consolidate as DisplayLevel , COUNT([HC CAT1]) AS cntStaffNO, [HC CAT1], [HC Cat5], [HC CAT6]
FROM HRC_MIS
WHERE (Period = @EndPeriod)
AND (Consolidate IN(Select * From dbo.Split(@Consolidate, ',')) OR (@Consolidate = '(Retail Consolidate)'))
GROUP BY Consolidate, Level3, [HC CAT1], [HC Cat5], [HC CAT6]
ORDER BY [HC CAT1]
End
IF @Consolidate != '(Retail Consolidate)' and @Level3 = '(LEVEL3)'
Begin
SELECT Level3 as DisplayLevel, COUNT([HC CAT1]) AS cntStaffNO, [HC CAT1], [HC Cat5], [HC CAT6]
FROM HRC_MIS
WHERE (Period = @EndPeriod)
AND Consolidate = @Consolidate
AND (Level3 IN (Select * From dbo.Split(@Level3, ',')))
GROUP BY Level3, [HC CAT1], [HC Cat5], [HC CAT6]
ORDER BY Level3
End
ELSE --IF @Level3 <> '(LEVEL3)'
Begin
SELECT Division as DisplayLevel, COUNT([HC CAT1]) AS cntStaffNO, [HC CAT1], [HC Cat5], [HC CAT6]
FROM HRC_MIS
WHERE (Period = @EndPeriod)
AND Level3 IN (Select * From dbo.Split(@Level3, ','))
GROUP BY Division, [HC CAT1], [HC Cat5], [HC CAT6]
ORDER BY Division
End
January 27, 2010 at 6:56 am
you are trying to assign a default value (null) to a local varable
January 27, 2010 at 6:59 am
Yes that was the problem, you'll notice on my second post that I have removed it.
Thanks for feedback
January 27, 2010 at 7:09 am
sorry I was typing the repsonse when you posted your answer so didn't see it until it was too late.
Glad it is sorted out .
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply