WaitFor Delay not working in Azure SQL DW

2.4k Views Asked by At

I am trying to run this simple code in SSMS connected to Azure SQL DW and it fails. I have tried some different variation but none of them seems to be working.

BEGIN
PRINT 'Hello ';
WAITFOR DELAY '00:00:02'
PRINT 'Another';
END

Msg 103010, Level 16, State 1, Line 47
Parse error at line: 2, column: 16: Incorrect syntax near ';'.
2

There are 2 best solutions below

0
GregGalloway On BEST ANSWER

Correct. At the moment the WAITFOR statement isn't supported in Azure SQL DW. Note on the documentation for this statement near the top it says whether this statement "applies to" Azure SQL DW.

Please vote for this feature suggestion to help Microsoft prioritize this enhancement.

It may not help you much, but you can connect to the master database under a separate connection and run the WAITFOR statement.

1
Onur Omer On

A bloody workaround until we have that simple built-in function:

1- Create a Proc Named "spWait" as follows:

CREATE PROC spWait @Seconds INT
AS
BEGIN

    DECLARE @BEGIN DATETIME
    DECLARE @END DATETIME 

    SET @BEGIN = GETDATE()
    SET @END = DATEADD("SECOND",@Seconds,@BEGIN)

    WHILE (@BEGIN<@END)
    BEGIN   
        SET @BEGIN=GETDATE()
    END

END

2- Call this between your commands

--Do this

EXEC spWait 3

--Do that