I’ve created a function for retrieving the translations of database columns in MS SQL Server 2005, depending on the selected language code (e.g. ‘el-GR’). The function itself works correctly, but I am unable to use its result as the Alias for the retrieved columns.
This is the code I’m using:
SELECT
tblAuditors.[Full Name] as dbo.GetLocalizedGridTranslation('Auditor Name', @languageCode)
FROM tblCompanyAuditors
Does anyone know how I can trick the SQL Server into allowing me to use the function as an Alias name?
Wrap the alias in brackets
[]:Apart from that, is it a typo that you’ve queried a table
tblCompanyAuditorsbut the column is from tabletblAuditors?Edit: I’ve only just noticed that the column alias itself should be the result of a function.
Does that make sense? An alias is a column for all records, and a function will be executed on every record. If that’s a stored-procedure i would recommend to store the result in a variable and use that as column alias in dynamic sql.