Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Must declare the scalar variable "@@procid"

I'm pretty new to SQL Server. I'm trying to create a simple procedure to get the name of the current procedure name for debugging purpose.

This is the code.

-- ======================================================================
-- Create Stored Procedure Template for Azure SQL Data Warehouse Database
-- ======================================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [stg].[test_procid]
AS
BEGIN
    DECLARE @objectname VARCHAR(200);
    SET @objectname = QUOTENAME(object_schema_name(@@procid)) + '.' + QUOTENAME(object_name(@@procid));
END
GO

When I execute this code, I get this error.

Msg 137, Level 16, State 1, Line 8
Must declare the scalar variable "@@procid".

Not sure what I'm doing wrong. Please help

Update: Thanks @Larnu and @David. I'm using Azure SQL Data Warehouse and I think that is the reason. I want this information to be passed on to another procedure in a generic way than hardcoding the procedure name.

Is there any way to do it in Azure Data Warehouse?

like image 950
BKM Avatar asked Sep 14 '25 17:09

BKM


1 Answers

@@procid is not supported on Azure SQL Data Warehouse. This is documented.

It works fine on Azure SQL Database.

like image 107
David Browne - Microsoft Avatar answered Sep 17 '25 20:09

David Browne - Microsoft



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!