Re: How can I force a pause in program execution?

From: Dan Guzman (danguzman_at_nospam-earthlink.net)
Date: 03/26/04


Date: Fri, 26 Mar 2004 11:13:20 -0600


> I'm attempting to build a table and then immediately insert into
> said table. The problem is that the table creation isn't complete before
the
> insert command fires.

You can create a table and immediately insert data like the example below.

'GO' is not a T-SQL statement. It is a batch delimiter recognized by SQL
tools like Query Analyzer. These utilities send the batch of SQL statements
preceding the 'GO' and SQL Server processes the statements in the batch
synchronously so there's no need to explicitly wait for the preceding
statement to finish. The scope of declared variables is local to the
batch.

DECLARE @MyData int
SET @MyData = 1
CREATE TABLE MyTable
    (
    MyColumn int
    )
INSERT INTO MyTable VALUES(@MyData)
GO

-- 
Hope this helps.
Dan Guzman
SQL Server MVP
"Ken Sturgeon" <ksturgeon@genelco.com> wrote in message
news:uywPg%230EEHA.3576@tk2msftngp13.phx.gbl...
> In VB one can invoke the DoEvents command to force a pause in program
> execution until the last statement execution has completed. I've found no
> similar concept in TransactSQL other than using the GO statement. The
> problem is that when I invoke the GO command I loose all of my parameter
and
> variable values.
>
> Is there an alternative way in which I can force a pause without loosing
the
> values? I'm attempting to build a table and then immediately insert into
> said table. The problem is that the table creation isn't complete before
the
> insert command fires.
>
> I thank you in advance for your assistance.
>
> Ken Sturgeon
>
>


Relevant Pages

  • Re: Inserting Multiple Rows
    ... In addition to that [BCP, BULK INSERT, DTS], it might be worth mentioning below two things. ... Group several INSERT in the same transaction. ... Each batch requires a network roundtrip, ... mean what we see as "GO" in Query Analyzer and the method you use in ADO.NET to send the command to SQL Server ...
    (microsoft.public.sqlserver.server)
  • Re: testing @@error in SP
    ... Some errors in SQL Server cause the abortion of the T-SQL batch they are. ... the batch and can be handled with an error handler. ...
    (microsoft.public.sqlserver.programming)
  • Re: Inserting Multiple Rows
    ... In addition to that [BCP, BULK INSERT, DTS], it might be worth mentioning below two things. ... Group several INSERT in the same transaction. ... Each batch requires a network roundtrip, ... mean what we see as "GO" in Query Analyzer and the method you use in ADO.NET to send the command to SQL Server ...
    (microsoft.public.sqlserver.programming)
  • Re: Inserting Multiple Rows
    ... In addition to that [BCP, BULK INSERT, DTS], it might be worth mentioning below two things. ... Group several INSERT in the same transaction. ... Each batch requires a network roundtrip, ... mean what we see as "GO" in Query Analyzer and the method you use in ADO.NET to send the command to SQL Server ...
    (microsoft.public.dotnet.framework.aspnet)