Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2012-07-16 : 03:24:23
|
Hi,HOw is it possible to rename the field of a table variable in sql?Thanks |
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2012-07-16 : 04:49:52
|
Sorry, but no way, unless you declare another table variable (with new column name) and shift data to new one--------------------------http://connectsql.blogspot.com/ |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-07-16 : 05:15:35
|
ALTER, DROP, and TRUNCATE are not possible on a table variableMadhivananFailing to plan is Planning to fail |
 |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2012-07-16 : 05:22:34
|
Is it possible to alter a field name of a temp table based on a variable?i.e. declare @Qrt smallint = 9select field1, 'field' + @Qrt = field2 field3 from #tblMainthe result is the same except one of the field name is different.The above will be:field1, field9 field3? |
 |
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2012-07-16 : 05:54:45
|
NOP, you can't rename a temporary table column--------------------------http://connectsql.blogspot.com/ |
 |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2012-07-16 : 05:59:59
|
Thanks |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-07-16 : 08:40:03
|
quote: Originally posted by lionofdezert NOP, you can't rename a temporary table column--------------------------http://connectsql.blogspot.com/
Why?create table #t(empid int, firstname varchar(10))GOexec tempdb..sp_rename '#t.firstname','#t.first_name','column'MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|