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 |
|
igor92128
Starting Member
23 Posts |
Posted - 2010-01-12 : 16:36:24
|
| I have a temp table:declare @temp_table table( uid uniqueidentifier, first varchar(50), choice varchar(5))insert into @temp_table (uid, first, choice)select (...from ...I want choice to be overwritten with 'YES' when inserting into @temp_table. What is the best way to do this?Thanks. |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-01-12 : 16:49:20
|
Your question is not very clear....you want choice varchar(5) to always have a value of 'YES' for all rows..Then just do this in the insert..insert into @temp_table (uid, first, choice)select uid,first,'YES'from table1 |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2010-01-12 : 20:37:52
|
Alternatively, you could do the following:declare @temp_table table(uid uniqueidentifier,first varchar(50),choice varchar(5) default 'Yes')insert into @temp_table (uid, first) values (newid(),'FirstThingie');insert into @temp_table (uid, first) values (select....);select * from @temp_table As an aside, in the above, what you are declaring is a table variable, rather than a temporary table. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-13 : 01:22:31
|
quote: Originally posted by sunitabeck Alternatively, you could do the following:declare @temp_table table(uid uniqueidentifier,first varchar(50),choice varchar(5) default 'Yes')insert into @temp_table (uid, first) values (newid(),'FirstThingie');insert into @temp_table (uid, first) values (select....);select * from @temp_table As an aside, in the above, what you are declaring is a table variable, rather than a temporary table.
please note that for insert... select you don't need values clause |
 |
|
|
|
|
|
|
|