2

If I have the SQL query:

select
    project.Employee,
    project.HoursQuantity,
    convert(varchar(10), project.EntryDate, 120)
from db.Project as project 

It will return ProjectHours and HoursQuantity with the proper column name, but will return EntryDate as (No column name).

How do I fix this or rename the column so that a title will show up on the table returned to the user?

I thought the data would remain in the same column, but I guess it moves to a new column. I tried aliasing it and a couple of other things but it hasn't worked.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Jake Steele
  • 305
  • 3
  • 13

2 Answers2

8

Give it an alias with the same name

select
    project.Employee,
    project.HoursQuantity,
    convert(varchar(10), project.EntryDate, 120) as EntryDate
from db.Project as project 
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
0

My preferred method for column aliasing is alias = expression:

Bad Habits to Kick : Using AS instead of = for column aliases - Aaron Bertrand - 2012-01-23

select
    project.Employee,
    project.HoursQuantity,
    EntryDate = convert(varchar(10), project.EntryDate, 120)
from db.Project as project 

Valid column alias methods:

select 1 as x;    -- #1
select x = 1;     -- #2
select 'x' = 1 ;  -- #3
select [x] = 1 ;  -- #4
select 1 x;       -- #5
select 1 as 'x';  -- #6
select 1 'x';     -- #7
select 1 as [x];  -- #8
select 1 [x];     -- #9
Community
  • 1
  • 1
SqlZim
  • 37,248
  • 6
  • 41
  • 59