Quick nested SQL question

Capodecina
Permabanned
Joined
31 Dec 2003
Posts
5,172
Location
Barrow-In-Furness
How can I give a nested select statement a column name? I'd like the column name for the nested field to be CodeName..

Code:
SELECT ID, TimeCode, (SELECT CodeName FROM tblCodes WHERE tblHours.TimeCode = tblCodes.CodeID), Hours, Date, UserName, Comments, Approved FROM tblHours

At the moment it shows as "No column name" and I need to have one so I can bind data a ASP.net control to it.
 
How can I give a nested select statement a column name? I'd like the column name for the nested field to be CodeName..

Code:
SELECT ID, TimeCode, (SELECT CodeName FROM tblCodes WHERE tblHours.TimeCode = tblCodes.CodeID), Hours, Date, UserName, Comments, Approved FROM tblHours

At the moment it shows as "No column name" and I need to have one so I can bind data a ASP.net control to it.

You can use 'as', cant you?

Code:
SELECT ID, TimeCode, (SELECT CodeName FROM tblCodes WHERE tblHours.TimeCode = tblCodes.CodeID) as SomeColumnName, Hours, Date, UserName, Comments, Approved FROM tblHours
 
You can use 'as', cant you?

Code:
SELECT ID, TimeCode, (SELECT CodeName FROM tblCodes WHERE tblHours.TimeCode = tblCodes.CodeID) as SomeColumnName, Hours, Date, UserName, Comments, Approved FROM tblHours

Spot on thanks, I knew it would be something simple :)
 
Back
Top Bottom