| Author |
Topic |
|
ramotswa
Starting Member
6 Posts |
Posted - 2009-01-09 : 07:52:40
|
| Hello all,This may be an obvious one, but humour me.I want to do an insert on one table. Basically:Insert into table1 (fielda, fieldb, fieldc) VALUES((Select field1 from table2 where xyz), value1, value2);Does that make sense? Basically i want all the values that match the where clause in table2 to be put in with the static value1 and value2 's... Any help would be nice.ThanksRamo |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-01-09 : 07:54:47
|
| some thing like thistry itinsert into table1 ( fielda,fieldb,fieldc)select fielda,fieldb,fieldcfrom table2where xyz in ( value1,value2) |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-09 : 07:56:05
|
| Insert into table1 (fielda, fieldb, fieldc) selectfield1, @value1, @value2from table2 where cond.. |
 |
|
|
ramotswa
Starting Member
6 Posts |
Posted - 2009-01-09 : 08:01:28
|
| Thanks for the quick reply.. but not quite what I was looking for.The value1 and value2 are actually integers. (i.e. 4 and 19) and they aren't changing. These values dont exist in either table. What does the @ symbol do?Ramo |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-01-09 : 08:03:13
|
| I think you need thisinsert into table1 ( fielda,fieldb,fieldc)select fielda,value1,value2from table2 where xyz MadhivananFailing to plan is Planning to fail |
 |
|
|
ramotswa
Starting Member
6 Posts |
Posted - 2009-01-09 : 08:05:51
|
| so this is basically what I wanted to do:Insert into table1 (ContactID, periodID, trackID) values(SELECT contactid, FROM contacts WHERE ( (contacts.ContactTypeID)<>4 And (contacts.ContactTypeID)<>11 ) AND( (contacts.StatusTypeID)=6 or (contacts.StatusTypeID)=1) ),6, 59);No?Ramo |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-01-09 : 08:06:58
|
| try thisInsert into table1 (ContactID, periodID, trackID)SELECT contactid,6,59FROM contacts WHERE( (contacts.ContactTypeID)<>4 And (contacts.ContactTypeID)<>11 )AND( (contacts.StatusTypeID)=6 or (contacts.StatusTypeID)=1) ) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-01-09 : 08:11:29
|
| Insert into table1 (ContactID, periodID, trackID) SELECT contactid, 6, 59FROM contacts WHERE ( (contacts.ContactTypeID)<>4 And (contacts.ContactTypeID)<>11 ) AND( (contacts.StatusTypeID)=6 or (contacts.StatusTypeID)=1) ;MadhivananFailing to plan is Planning to fail |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-09 : 08:13:09
|
| Insert into table1 (ContactID, periodID, trackID) SELECT contactid, 6,59FROM contacts WHERE ( ContactTypeID<>4 And ContactTypeID<>11 ) AND( StatusTypeID=6 or StatusTypeID=1 ) |
 |
|
|
ramotswa
Starting Member
6 Posts |
Posted - 2009-01-09 : 08:29:21
|
| Thank you all.. you are all very clever!!:)Ramo |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-09 : 08:36:00
|
quote: Originally posted by ramotswa Thanks for the quick reply.. but not quite what I was looking for.The value1 and value2 are actually integers. (i.e. 4 and 19) and they aren't changing. These values dont exist in either table. What does the @ symbol do?Ramo
@ symbol stands for local variables or parameters in sql server |
 |
|
|
|