Latest

6/recent/ticker-posts

Header Ads Widget

Cursor in sql to check all users login status

In this article we learn how we can run a cursor in sql server to validate all users.

declare @field1 varchar(100)
declare @field2 varchar(100)

declare cur CURSOR LOCAL for
    select field1, field2 from sometable where someotherfield is null

open cur

fetch next from cur into @field1, @field2

while @@FETCH_STATUS = 0 BEGIN

    --execute your sproc on each row
    exec yourloginprocedure @field1, @field2

    fetch next from cur into @field1, @field2
END

close cur 
deallocate cur

Post a Comment

0 Comments