Just Code‎ > ‎

TSQL - Aliases for column names from Stored Procedure results

posted Apr 3, 2015, 1:46 PM by Peter Henell   [ updated Apr 3, 2015, 1:47 PM ]
In Sql Server 2012 there was a feature introduced called WITH RESULT SETS which allow (among other things) to put aliases on the result set of stored procedures.

This example will put aliases on all the columns returned from the stored procedure.
create procedure #testing as
begin
    select a, b, c from (values (1, 2, 3), (11, 22, 33)) as t(a, b, c);
end;
go

exec #testing
WITH RESULT SETS
(
 ( 
  [Amazing New Name for A]             NVARCHAR(100),
  [The B column is also renamed]  NVARCHAR(20),
  [The C column Renamed]         NVARCHAR(30)
 ) 
);
Comments