iterate

  • If exists (select fieldID from #tmploginfo where status <> 0

    group by fieldID

    having count(*) > 0)

    begin

    backup log rdb to disk = N'C:\rdb1.trn'

    End

    I want to iterate this query using a loop as many as 5 times max. I would like someone to help me out.

  • DECLARE @i tinyint = 1;

    WHILE @i <= 5

    BEGIN

    If exists (select fieldID from #tmploginfo where status <> 0

    group by fieldID

    having count(*) > 0)

    begin

    backup log rdb to disk = N'C:\rdb1.trn'

    End;

    SET @i = @i+1;

    END

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • I hope this was for an example or homework and not for production.

  • Unfortunately, I have to do this in production. However, I will be running this query when the production is down.

Viewing 4 posts - 1 through 3 (of 3 total)

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