List of backup which failed at least 3 times sequentially

  • I have a table like below, and i want to get a result like this:

    declare @Failed3Times table(id int, name varchar(12),status varchar(12))

    insert into @Failed3Times values (1,'FirstDb','FAILED'),

    (2,'SecondDb','SUCCESS'),

    (3,'FirstDb','FAILED'),

    (4,'FirstDb','FAILED'),

    (5,'FirstDb','FAILED'),

    (6,'FirstDb','SUCCESS')

    ,(7,'FirstDb','FAILED'),

    (8,'FirstDb','FAILED')

    select

    id,

    name,

    status,

    FailedRank ??????????????

    from @Failed3Times

    order by id

    Result should be:

    id name status Rank1

    ----------- ------------ ------------ --------------------

    1 FirstDb FAILED 1

    2 SecondDb SUCCESS 1

    3 FirstDb FAILED 1

    4 FirstDb FAILED 2

    5 FirstDb FAILED 3

    6 FirstDb SUCCESS 1

    7 FirstDb FAILED 1

    8 FirstDb FAILED 2

    I want to list the backups which failed 3 times repeatingly?

    How do i achive this in SQL Server 2008?

  • would seem like you need to use ranking functions http://msdn.microsoft.com/en-us/library/ms189798.aspx

  • I want to write an iterative query with resetting counter if backup succeeed?

    I achive this with Cursors but, i want to learn to do this with an iterative SQL Statement?

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

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