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 |
|
free_loader
Starting Member
3 Posts |
Posted - 2005-11-11 : 19:44:59
|
| I have three tables t1, t2, t3. I want to insert a new row in t1. I am using access 2000 with sql commands for the queries. There are 4 colums in t1. I know the values of two of the colums. The remaining two columns values are going to be look up in the other 2 tables, 1 value from t2 table and the other value from t3.. I need this to be in one statement. From what I have seen you can either use insert with values() or you can populate your table with unkown values from another table. But I want to do both, since 2 of my values are known and the other 2 need to come from another table.I hope that I made it clear enough. Can anyone help meThanks |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-11-11 : 19:50:05
|
is this what you want?insert into t1 (col1, col2, col3, col4)select 'knownValue1', 'knownValue2', t2.col1, t3.col1from t2 join t3 on t2.id = t3.idGo with the flow & have fun! Else fight the flow |
 |
|
|
free_loader
Starting Member
3 Posts |
Posted - 2005-11-11 : 19:58:43
|
| insert into t1 (col1, col2, col3, col4)select 'knownValue1', 'knownValue2', t2.col1, t3.col1from t2 join t3 on t2.id = t3.idnot exactlycol1 I know and I am going to hardcode it ex. 'free'col2 I know and I am going to hardcode it ex. 'loader'col3 will be from t2 // where t2.id = t3.id, t3.name = 'free'col4 will be from t3 // where t3.job = t2.job, t2.last = 'loader'something like that |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-11-11 : 20:06:33
|
something like:insert into t1 (col1, col2, col3, col4)select 'free', 'loader', t2.col1, t3b.col1from table2 t2 join table3 t3a on t2.id = t3a.id and t3a.name = 'free' join table3 t3b on t2.job = t3b.job and t2.last = 'loader' Go with the flow & have fun! Else fight the flow |
 |
|
|
free_loader
Starting Member
3 Posts |
Posted - 2005-11-11 : 20:15:25
|
| That might look like it would work I will try it. It will be about 30 min before i can reply Thanks |
 |
|
|
|
|
|
|
|