Posts

Showing posts from May, 2010

MSSQL Cannot drop database because it is currently in use

USE   Master ; GO ALTER   DATABASE   AnnoyingDb   SET   SINGLE_USER   WITH   ROLLBACK   IMMEDIATE GO -- and finally DROP   DATABASE AnnoyingDb ; GO

Avoiding a cursor in mssql, with a loop

set   @LoopIndexer   =  1 set   @LoopId   =  1 -- loop through each item while  ( @LoopIndexer <= @CountTtbwsid ) begin -- find the next available row, avoiding a cursor while   not   exists   ( select   @LoopId   from   #ttbwsid   where   id   =   @LoopId ) set   @LoopId   =   @LoopId   +  1 -- work to be done inside cursor -- value for row can be retrieved with a simple select set   @LoopIndexer   =   @LoopIndexer   +  1 set   @LoopId   =   @LoopId   +  1 end