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 |
|
KidSQL
Yak Posting Veteran
88 Posts |
Posted - 2005-05-24 : 09:38:07
|
| I have a tmp table #mytable which consists of several columns like:Date ID Value1 Value2 Value3all columns are nullable in this table and carry null values where no value is inserted. What I need to do is insert a bunch of rows into this table for the columns Date, ID, and Value1, as I need to update the Value2 and Value3 later. Here's the conventional wisdom (I believe):insert into #mytable(Date, ID, Value1)values('1990-01-01', 'ABC', 20)which works fine, as it leaves Value2 and Value3 null. My question is: how do I insert a whole bunch of rows into this table by specifying that I'm inserting values for Date, ID, Value only?Put another way, I get this information from another table (call it sourcetable) and I'd like to select, say, 20 rows from this table to insert into the first 3 columns of my tmp table. Can someone show me how to structure such a query without having to explicitly list every value? Would I substitute something like: 'select * from sourcetable' for the () bit under values somehow?Any help would be much appreciated.(PS: Note I cannot create the temp table and then modify later by adding columns as I must do all this in a loop and I am unable to alter #mytable between 'begin' and 'end') |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2005-05-24 : 09:41:05
|
| insert into tablea (cola1, cola2, cola3)select colb1, colb2, colb3 from tableb |
 |
|
|
KidSQL
Yak Posting Veteran
88 Posts |
Posted - 2005-05-24 : 09:44:52
|
| Thank you very much!! |
 |
|
|
|
|
|
|
|