0

Consider the following stored procedure for fetching some data

SELECT 
    MatType_Id as 'ID', MatType_Code as 'Code', MatType_Name as 'Name',          
    Status_Id as 'Sid', 
    CASE 
        WHEN Status_Id = 1 THEN 'Active' 
        ELSE 'In Active' 
    END AS Status         
FROM 
    MM.MM_MATTYPE 

I want to get all column 'alias' names in above stored procedure which are ID, Code, Name, Sid and status through a query.

I tried with the following query

select referenced_minor_name    
from sys.dm_sql_referenced_entities('Sp_Name','object')

But its returning only actual column names MatType_Id, MatType_Code, MatType_Name, Status_Id and its not returning the last column status

Please someone help me to get all column alias names of a stored procedure in SQL Server.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
KRIZ
  • 1
  • 2
  • 2
    Duplicate: [Retrieve column definition for stored procedure result set](http://stackoverflow.com/questions/7368864/retrieve-column-definition-for-stored-procedure-result-set) – Ross Presser Oct 30 '13 at 05:54
  • Is this what you're after? http://stackoverflow.com/questions/14574773/retrieve-column-names-and-types-of-a-stored-procedure Hope it helps. – John Oct 30 '13 at 05:56
  • @RossPresser your solution not giving the extra column 'status' adding using case in my sp.. – KRIZ Oct 30 '13 at 07:16
  • @john OpenQuery also not returning that extra column 'status' in my sp! someone help me please.. – KRIZ Oct 30 '13 at 07:36

0 Answers0