SQL Server (TSQL) - Is it possible to EXEC statements in parallel?

Posted by Investor5555 on Stack Overflow See other posts from Stack Overflow or by Investor5555
Published on 2010-12-31T18:57:39Z Indexed on 2011/01/01 12:53 UTC
Read the original article Hit count: 273

Filed under:
|
|

SQL Server 2008 R2

Here is a simplified example:

EXECUTE sp_executesql N'PRINT ''1st '' + convert(varchar, getdate(), 126) WAITFOR DELAY ''000:00:10'''
EXECUTE sp_executesql N'PRINT ''2nd '' + convert(varchar, getdate(), 126)'

The first statement will print the date and delay 10 seconds before proceeding. The second statement should print immediately.

The way T-SQL works, the 2nd statement won't be evaluated until the first completes. If I copy and paste it to a new query window, it will execute immediately.

The issue is that I have other, more complex things going on, with variables that need to be passed to both procedures.

What I am trying to do is:

  • Get a record
  • Lock it for a period of time
  • while it is locked, execute some other statements against this record and the table itself

Perhaps there is a way to dynamically create a couple of jobs?

Anyway, I am looking for a simple way to do this without having to manually PRINT statements and copy/paste to another session.

Is there a way to EXEC without wait / in parallel?

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server