0

I am using system procedure as follow to get Column Name from procedure.

exec Sp_depends @procedure-name

but it is not returning alias column name.

I have following query in procedure.

SELECT ID, E_No As E_No, Case When E_SAL BETWEEN 10000 AND 50000 THEN 1 ELSE 0 END E_ACTIVE
FROM E_MAST
WHERE E_SAL BETWEEN 10000 AND 50000"

I need all column , including alias column but i cannot return alias. How can i return alias column name from procedure?

current result is :

**name         type   updated selected  column**
dbo.E_MAST  user table  no      yes       ID
dbo.E_MAST  user table  no      yes       E_NO
dbo.E_MAST  user table  no      yes       E_SAL

i need this result :

**name         type   updated selected  column**
dbo.E_MAST  user table  no      yes       ID
dbo.E_MAST  user table  no      yes       E_NO
dbo.E_MAST  user table  no      yes       E_SAL
dbo.E_MAST  user table  no      yes       E_ACTIVE
Ritesh Khatri
  • 484
  • 4
  • 13

1 Answers1

1

sp_depends stored procedure is used to

Displays information about database object dependencies, such as the views and procedures that depend on a table or view, and the tables and views that are depended on by the view or procedure.

So it correctly identifies all the columns that your stored procedure depends on. E_ACTIVE is an alias, it's not a database object, so there cannot be a dependency on it.


You can also check this question and its answer: Retrieve column definition for stored procedure result set to see how you can get the metadata about a stored proc.

Community
  • 1
  • 1
Szymon
  • 42,577
  • 16
  • 96
  • 114