Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 26th, 2012  |  syntax: None  |  size: 0.65 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. SQL Server stored proc - need to return resultset before execution finishes
  2. BEGIN
  3. DECLARE @ID int
  4.  
  5.  
  6. IF EXISTS(
  7.     SELECT      ID
  8.     FROM        Competitions
  9.     WHERE       COALESCE(Won, 0) != 1
  10.     AND         WinningTime < GetDate()
  11. )
  12. BEGIN
  13.     --If we have a winner then select the row (whilst locking the table to prevent multiple winners), then update the row to mark the competition as being won
  14.     BEGIN TRAN
  15.  
  16.         --Select row
  17.  
  18.         --Update row to mark it as 'Won'
  19.  
  20.     COMMIT TRAN
  21.  
  22.     --** We need to return the previous select before executing this **
  23.  
  24.     WAITFOR DELAY '000:10:00'
  25.     EXECUTE ResetCompetition @CompID = @ID;
  26.  
  27. END
  28. END