How to fix Error 584 on Windows Server 2025 / Windows 11

Troubleshooting Guide: SQL Server Error 584 – “Select Into Not Allowed in WAITFOR Queries”

Why This Error Happens

This error occurs because SQL Server’s query engine does not permit combining a SELECT INTO statement within the same batch or scope as a WAITFOR clause, as these two operations conflict at the execution plan compilation level. The root cause is typically a poorly structured T-SQL script where developers attempt to delay table creation using WAITFOR DELAY or WAITFOR TIME while simultaneously projecting result sets into a new table. This is a T-SQL syntax/logic restriction rather than a permissions or connectivity issue, meaning it cannot be resolved through server configuration alone—it requires query refactoring.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Query Block

  • Open SQL Server Management Studio (SSMS) 21 or Azure Data Studio connected to your SQL Server 2025 instance.
  • Locate the specific stored procedure or script triggering Error 584 by checking the SQL Server Error Log at C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG.
  • Search for the exact batch containing both WAITFOR and SELECT...INTO keywords.

Step 2: Separate the WAITFOR and SELECT INTO Logic

  • Break the single batch into two distinct, sequential batches separated by a GO statement or explicit batch terminator.
  • Move the WAITFOR DELAY '00:00:05' (or equivalent) command to execute before the SELECT INTO statement, ensuring it is not nested in the same statement scope.
  • Example fix:
  WAITFOR DELAY '00:00:05';
  GO
  SELECT * INTO #TempTable FROM SourceTable;

Step 3: Replace WAITFOR with SQL Agent Job Scheduling (If Applicable)

  • If the intent was to delay a data import task, migrate the logic to a SQL Server Agent Job with a scheduled start time instead of using inline WAITFOR.
  • Navigate to SQL Server Agent > Jobs > New Job in SSMS and configure the schedule under the Schedules tab.
  • This removes the need for WAITFOR entirely within the T-SQL batch logic.

Step 4: Validate Compatibility Level Settings

  • Check the database compatibility level, as legacy compatibility modes (below 160) may alter how batch parsing handles WAITFOR.
  • Run the following command to verify and update if necessary:
  ALTER DATABASE [YourDBName] SET COMPATIBILITY_LEVEL = 170;

Alternative or Verification Steps

  • Re-run the modified script in a test environment; if Error 584 no longer appears in the Messages tab of SSMS, the batch separation was successful.
  • As an alternative, encapsulate the SELECT INTO logic within a stored procedure and call that procedure after a WAITFOR command in the master calling script, ensuring the two operations remain in distinct execution contexts.