October 12, 2014 at 6:56 am
I get a red squiggle below the first IF statement.
Can't figure out the correct syntax.
Any suggestions?
TIA,
Julian
Netherlands
UNION ALL
IF ((SELECT Flexpool FROM Huizen WHERE IDHuis = @LOCATIECODE ) = 'WAAR')
SELECTM.LOCATIECODE, M.AfdelingZPT, DATEPART(ISO_WEEK, M.Begindatum) wk, M.DienstGroep, NULL Leeg, NULL Leeg, SUM(M.Hrs) AS Uren
FROMDRPHrsManual M
WHEREM.LocatieCode = @LocatieCode
AND M.AfdelingZPT = @Afdeling
AND M.Begindatum between @BeginDatum and @BeginDatum+6
AND M.DienstGroep = 'FLEXPOOL'
AND M.NiveauZPT <> 'STA'
AND M.NiveauZPT IN ('1','2','2+','3','4','5')
GROUP BY M.LocatieCode, DATEPART(ISO_WEEK, M.Begindatum), M.AfdelingZPT, M.DienstGroep
ELSE
-- FINISH THE CODE BELOW....
SELECT D.LOCATIECODE, D.AfdelingZPT, DATEPART(ISO_WEEK, D.Begindatum) WK, D.DienstGroep, NULL Leeg, NULL Leeg, SUM(D.Duur)/60.0 AS UREN
FROMDRPDATA D
WHERED.LocatieCode = @LocatieCode
--AND D.AfdelingZPT = @Afdeling
AND D.Begindatum between @BeginDatum and @BeginDatum+6
AND D.DienstGroep = 'DAG/AVOND'
AND D.FlexVast = 'FLEX'
AND D.NiveauZPT <> 'STA'
AND D.NiveauZPT IN ('1','2','2+','3','4','5')
GROUP BY D.LocatieCode, DATEPART(ISO_WEEK, D.Begindatum), D.AfdelingZPT, D.DienstGroep
-- GET PNIL FLEX
UNION ALL
October 12, 2014 at 7:05 am
I recommend to assign the result of the query against Huizen in a separate variable and use that result in the query to eliminate the IF .. ELSE control flow.
SELECT @Flexpool = Flexpool FROM Huizen WHERE IDHuis = @LOCATIECODE
...
UNION ALL
SELECTM.LOCATIECODE, M.AfdelingZPT, DATEPART(ISO_WEEK, M.Begindatum) wk, M.DienstGroep, NULL Leeg, NULL Leeg, SUM(M.Hrs) AS Uren
FROMDRPHrsManual M
WHEREM.LocatieCode = @LocatieCode
AND M.AfdelingZPT = @Afdeling
AND M.Begindatum between @BeginDatum and @BeginDatum+6
AND M.DienstGroep = 'FLEXPOOL'
AND M.NiveauZPT <> 'STA'
AND M.NiveauZPT IN ('1','2','2+','3','4','5')
AND @Flexpool = 'WAAR'
GROUP BY M.LocatieCode, DATEPART(ISO_WEEK, M.Begindatum), M.AfdelingZPT, M.DienstGroep
UNION ALL
-- FINISH THE CODE BELOW....
SELECT D.LOCATIECODE, D.AfdelingZPT, DATEPART(ISO_WEEK, D.Begindatum) WK, D.DienstGroep, NULL Leeg, NULL Leeg, SUM(D.Duur)/60.0 AS UREN
FROMDRPDATA D
WHERED.LocatieCode = @LocatieCode
--AND D.AfdelingZPT = @Afdeling
AND D.Begindatum between @BeginDatum and @BeginDatum+6
AND D.DienstGroep = 'DAG/AVOND'
AND D.FlexVast = 'FLEX'
AND D.NiveauZPT <> 'STA'
AND D.NiveauZPT IN ('1','2','2+','3','4','5')
AND @Flexpool <> 'WAAR'
GROUP BY D.LocatieCode, DATEPART(ISO_WEEK, D.Begindatum), D.AfdelingZPT, D.DienstGroep
-- GET PNIL FLEX
UNION ALL
October 12, 2014 at 7:26 am
Great, thank you Lutz.
Cheers,
Julian
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy