CASE or IF ... THEN around INSERT statements

  • I have a bunch of INSERT statements around which I want to use CASE or IF .. THEN.

    -- Test for @MeeTellen

    DECLARE@MeeTellen varchar(9)

    SELECT@MeeTellen = Meetellen FROM HuisAfdeling WHERE IDHuis = @IDHuis AND IDAfd = @IDAfd

    I could put this in the WHERE clause

    and @MeeTellen <> 'no'

    but it would be more clear and faster(?) if I put the condition around all INSERT statements.

    How do I write the code?

    TIA,

    Julian

    -- HRS VAST

    INSERT INTO @T (JAAR, WEEK, AfdelingZPT, HrsVast)

    (

    SELECTDBO.ISOyear(Begindatum) Jaar, datepart(ISO_WEEK,Begindatum) [Week], AfdelingZPT, sum(DUUR/60.0) HrsVast

    FROM DRPDATA

    WHERE LocatieCode = @IDHuis

    and AfdelingZPT = @IDAfd

    AND DBO.ISOyear(Begindatum) = @Jaar

    and OEGroep = 'zorg'

    AND NiveauZPT IN ('1','2','2+','3','4','5')

    and FlexVast = 'vast'

    and DienstGroep = 'Dag/Avond'

    GROUP BY DBO.ISOyear(Begindatum), datepart(ISO_WEEK,Begindatum), AfdelingZPT

    );

    -- HRS OVERIG

    INSERT INTO @T (JAAR, WEEK, AfdelingZPT, HrsOverig )

    (

    SELECTDBO.ISOyear(Begindatum) Jaar, datepart(ISO_WEEK,Begindatum) [Week], AfdelingZPT, sum(DUUR/60.0) HrsOverig

    FROM DRPDATA

    WHERE LocatieCode = @IDHuis

    and AfdelingZPT = @IDAfd

    AND DBO.ISOyear(Begindatum) = @Jaar

    and OEGroep = 'zorg'

    AND NiveauZPT IN ('1','2','2+','3','4','5')

    and FlexVast = 'vast'

    and DienstGroep = 'Overig'

    GROUP BY DBO.ISOyear(Begindatum), datepart(ISO_WEEK,Begindatum), AfdelingZPT

    );

  • Got it.

    IF @MeeTellen <> 'NEE'

    BEGIN

    -- HRS VAST

    INSERT INTO @T (JAAR, WEEK, AfdelingZPT, HrsVast)

    (

    SELECTDBO.ISOyear(Begindatum) Jaar, datepart(ISO_WEEK,Begindatum) [Week], AfdelingZPT, sum(DUUR/60.0) HrsVast

    FROM DRPDATA

    WHERE LocatieCode = @IDHuis

    and AfdelingZPT = @IDAfd

    AND DBO.ISOyear(Begindatum) = @Jaar

    and OEGroep = 'zorg'

    AND NiveauZPT IN ('1','2','2+','3','4','5')

    and FlexVast = 'vast'

    and DienstGroep = 'Dag/Avond'

    --and @MeeTellen <> 'nee'

    GROUP BY DBO.ISOyear(Begindatum), datepart(ISO_WEEK,Begindatum), AfdelingZPT

    );

    .

    .

    .

    .

    END

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply