SQL Server Performance Forum – Threads Archive
Dynamic alias nameHi,
could you please tell me how can we creat dynamic alias name for select list. example : declare aliasIdname set aliasIdname = 10 select age1 as aliasIdname ,age2 aliasIdname +1 as from cutomer [?] Thanks & Regards
Great work may have to pass through these stages – ridicule, opposition, and then acceptance. Each man who thinks ahead of his time will probably be greatly misunderstood.- vivekananda
Why do you name them dynamically?
Madhivanan Failing to plan is Planning to fail
You have to use dynamic SQL in order to do it and need to wrap an EXEC() around your syntax after declaring the appropriate variables. Be careful, though, because dynamic SQL can be slow and if it can be avoided, it should be. I am assuming that you need it for some type of development reason, rather than aesthetics. Read the following:
http://www.sommarskog.se/dynamic_sql.html Madhivanan Failing to plan is Planning to fail