Search code examples
azure-sql-database

Azure SQL Database 'sp_executesql' not supported on this version of SQL Server


When I execute the following the code below on my Azure SQL Database I get the following error:

'sp_executesql' not supported on this version of SQL Server



EXECUTE sp_executesql @ColumnMetadataSQL, @ParmDefinition, @ColumnMetadataOUT=@ColumnMetadata OUTPUT;

I'm not sure why I'm getting this error as 'sp_executesql' is supported on Azure SQL Database

https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-executesql-transact-sql?view=sql-server-ver16

Any thoughts?


Solution

  • Azure SQL Database sp_executesql not supported on this version of SQL Server

    As its giving did not support this version error looks strange because the sp_executesql command is supported in SQL Server versions (nearly all) i.e. 2000, 2005, 2008, 2008R2, 2012, 2014 or higher.

    I tried to reproduce but it's working fine for me. with same SQL version as you.

    Code and Execution in SSMS and Azure Query editor:

    DECLARE @SQLString NVARCHAR(500); 
    DECLARE @ParmDefinition NVARCHAR(500);   
    DECLARE @SalesOrderNumber NVARCHAR(25);
      
    SET @SQLString = N'SELECT @taskObtainedScoreOUT = MAX(taskObtainedScore)  
        FROM  [dbo].[samplejson4]';  
    SET @ParmDefinition = N'@taskObtainedScoreOUT NVARCHAR(25) OUTPUT';    
    EXECUTE sp_executesql  @SQLString,@ParmDefinition,@taskObtainedScoreOUT = @SalesOrderNumber OUTPUT;  
     
    SELECT @SalesOrderNumber ;
    

    enter image description here enter image description here

    SQL version:

    enter image description here

    Once Check your code and query parameter if still issue persist the issue might be from azure server side for deeper investigation you can raise support ticket to Microsoft team from here.