Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL Server Stored Procedure - Wait for a Table to be Created

SQL Server Stored Procedure - Wait for a Table to be Created

Scheduled Pinned Locked Moved Database
databasehelpsql-serverwpfwcf
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    David_41
    wrote on last edited by
    #1

    Hello all. I have the following Stored Procedure:

    ALTER PROCEDURE [EventPortion].[24Start]
    AS

    IF object_id('[IntegratedTest1].[EventPortion].[244Q1]') is not null
    DROP TABLE [IntegratedTest1].[EventPortion].[244Q1]

    IF object_id('[IntegratedTest1].[EventPortion].[244Q2]') is not null
    DROP TABLE [IntegratedTest1].[EventPortion].[244Q2]

    IF object_id('[IntegratedTest1].[EventPortion].[244Q3]') is not null
    DROP TABLE [IntegratedTest1].[EventPortion].[244Q3]

    SELECT * Into [IntegratedTest1].[EventPortion].[244Q1] FROM IntegratedTest1.Event.MOE_2_4_DE_4_Q1

    While (object_id('[IntegratedTest1].[EventPortion].[244Q1]') is null)
    Begin
    WAITFOR DELAY '00:00:00.001';
    End

    Begin
    WAITFOR DELAY '00:00:01.000';
    End

    SELECT * Into [IntegratedTest1].[EventPortion].[244Q2] FROM IntegratedTest1.Event.MOE_2_4_DE_4_Q2

    While (object_id('[IntegratedTest1].[EventPortion].[244Q2]') is null)
    Begin
    WAITFOR DELAY '00:00:00.001';
    End
    SELECT * Into [IntegratedTest1].[EventPortion].[244Q3] FROM IntegratedTest1.Event.MOE_2_4_DE_4_Q3

    I want this code to drop the 3 tables if they exist. This works. Then run the first Select Into. IntegratedTest1.Event.MOE_2_4_DE_4_Q2 depends on (Selects from) 244Q1. The problem that I am having is that the second Select Into is being executed and I am getting a binding error that 244Q1 doesn't exist. So, the While Is Null Wait For loops are not working. If I just execute the Wait For 1 second delay, that does take 1 second to execute. If I just run the first select into and the 1 second delay, it takes about 1 second to execute. But if I run the first and second select into with the delays in between, there is no delay. I immediately get the binding error. Is there anything I can do about this seemingly odd behavior? Thanks, David Edit: I figured out a solution and wanted to post it. I modified the stored procedure to:

    ALTER PROCEDURE [EventPortion].[24Start]
    AS
    DROP TABLE [IntegratedTest1].[EventPortion].[244Q1]
    DROP TABLE [IntegratedTest1].[EventPortion].[244Q2]
    DROP TABLE [IntegratedTest1].[EventPortion].[244Q3]
    SELECT * Into [IntegratedTest1].[EventPortion].[244Q1] FROM IntegratedTest1.Event.MOE_2_4_DE_4_Q1
    SELECT * Into [IntegratedTest1].[EventPortion].[244Q2] FROM IntegratedTest1.Event.MOE_2_4_DE_4_Q2
    SELECT * Into [IntegratedTest1].[EventPortion].[244Q3] FROM IntegratedTest1.Event.MOE_2_4_DE_4_Q3
    DROP TABLE [IntegratedTest1].[EventPortion].[245Q1]
    DROP TABLE [IntegratedTest1].[EventPortio

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups