2
votes

I have one table named tblalias.which is having two columns cid, description

cid                  description
1                    Employee
2                    Join Date
3                    Retire Date

Like this three record is present

Now I have another table tblemployee. I want to write a query for tblemployee to get record but alias name for that query I want should come from tblalias

select nama as Employee,
       joindate as "Join Date",
       retiredate as "Retire Date" 
from tblemployee

If I change value is tblalias table to my select query should return new value as alias is it possible if yes how please help me

2
BTW: what do you mean by 'dynamically' ? Please explain. - wildplasser
dynamic mean the alias name in my select query will come from tblalias table that is not hard code - Deepak Kumar

2 Answers

2
votes

The only way to do this is with dynamic SQL. First fetch the alias names then build the final SQL and execute it.

There is no way doing this with a single "hardcoded" statement.

0
votes

If you want spaces in names you should quote them. (spaces in names is generally a bad Idea, but that's another matter)