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 |
|
frank2
Starting Member
35 Posts |
Posted - 2005-09-13 : 16:20:29
|
| I want to populate a temp table. I have a table MyTable containing 10 records. I need to copy out the five records where ID = 'ME' then change 'ME' to 'SENT' Then append those changed records back to MyTable. So MyTable will end up having a total of 15 records.I am guessing i have to query out the 5 records into a temp table change them and insert them back.Can I SELECT INTO a temp table? Ir do the entire task in a single SELECT? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-09-13 : 16:25:04
|
| INSERT INTO MyTable (Column1, Column2, Column3, Column4, Column5)SELECT Column1, Column2, Column3, 'SENT', Column5FROM MyTableWHERE Column4 = 'ME'Tara |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2005-09-13 : 16:27:22
|
[code]Create Table #MyTempTable (id varchar(100), a varchar(10))Insert Into #myTempTable Select 'You', 'Blah1'Insert Into #myTempTable Select 'You', 'Blah2'Insert Into #myTempTable Select 'Me', 'Blah3'Insert Into #myTempTable Select 'You', 'Blah4'Insert Into #myTempTable Select 'Me', 'Blah5'Insert Into #myTempTable Select 'Me', 'Blah6'Insert Into #myTempTable Select 'You', 'Blah7'Insert Into #myTempTable Select 'You', 'Blah8'Insert Into #myTempTable Select 'Me', 'Blah9'Insert Into #myTempTable Select 'Me', 'Blah10'Select * From #myTempTableInsert Into #myTempTableSelect Id = 'Sent', aFrom #myTempTableWhere id = 'ME'Select * From #myTempTableDrop Table #myTempTable[/code]Corey Co-worker on The Wizard of Oz "...those three midgets that came out and danced, the freaked me out when I was little. But they are ok now." |
 |
|
|
frank2
Starting Member
35 Posts |
Posted - 2005-09-13 : 16:30:42
|
| Thanks for the answers. You folks hit the nail on the head. :) |
 |
|
|
|
|
|
|
|