T-SQL Issues With Defining 'AS' I am creating a fully dynamic application but have ran into a bit of a hiccup. There are multiple 'undefined' fields that can be defined by the users. The only problem is redisplaying them. Currently they are showing as [UDF_0] to [UDF_7], i.e. :

SELECT [TABLE].[UDF_0],
       [TABLE].[UDF_1],
       [TABLE].[UDF_2],
       [TABLE].[UDF_3],
       [TABLE].[UDF_4],
       [TABLE].[UDF_5],
       [TABLE].[UDF_6],
       [TABLE].[UDF_7]
FROM [TABLE]


Would obviously display as:

UDF_0 || UDF_1 || etc...


What I would like to be able to do is display them something to this effect, but I can't for the life of me figure it out.

EXECUTE PROCEDURE [dbo].[GetProjectInfo] @Project varchar(100)

AS
BEGIN

SELECT [TABLE].[UDF_0] AS (SELECT [TBL_PROJECT_DESC].[UDF_0]
                           FROM [TBL_PROJECT_DESC]
                           WHERE [TBL_PROJECT_DESC].[PROJECT_NAME]=@Project),
       --etc....
FROM [TABLE]


Desired display would be :

Field Name 0 || Field Name 1 || etc...
You could try something like this.

declare @command varchar(8000)

set @command = 'select udf_0 as ' + (select udf_0
                                     from tbl_project_desc
                                     where project_name = @project) + 
               ' from table where column = value'

EXECUTE(@command)