NSS
NSS

Reputation: 2022

WaitFor Delay not working in Azure SQL DW

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 ';'.

Upvotes: 2

Views: 2754

Answers (2)

Onur Omer
Onur Omer

Reputation: 526

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

Upvotes: 3

GregGalloway
GregGalloway

Reputation: 11625

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.

Upvotes: 1

Related Questions