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 |
|
agarwasa2008
Posting Yak Master
109 Posts |
Posted - 2009-09-01 : 19:01:55
|
| insert into table1 (col1, col2, col3, col4)select col1, col2, col3, col4from table2 where col2=34but I want to insert col1=54 //different specific valuePlease adviceSA |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2009-09-01 : 19:18:36
|
| insert into table1 (col1, col2, col3, col4)select 54, col2, col3, col4from table2 where col2=34=======================================Men build too many walls and not enough bridges. -Isaac Newton, philosopher and mathematician (1642-1727) |
 |
|
|
agarwasa2008
Posting Yak Master
109 Posts |
Posted - 2009-09-01 : 19:47:39
|
| This works perfectly well. Thank you. Can someone translate it using variables? I am new to sql.Thanks!!SA |
 |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2009-09-01 : 19:50:07
|
| insert into table1 (col1, col2, col3, col4)select @Variable, col2, col3, col4from table2 where col2=34=======================================Men build too many walls and not enough bridges. -Isaac Newton, philosopher and mathematician (1642-1727) |
 |
|
|
agarwasa2008
Posting Yak Master
109 Posts |
Posted - 2009-09-01 : 19:55:21
|
| insert into table1 (col1, col2, col3, col4)select @Variable1, col2, col3, col4from table2 where col2=@Variable2Can I write it as above and how would I assign the variables the 2 values.SA |
 |
|
|
agarwasa2008
Posting Yak Master
109 Posts |
Posted - 2009-09-01 : 21:23:17
|
| I would really appreciate some feedback on this!!insert into table1 (col1, col2, col3, col4)select @Variable1, col2, col3, col4from table2 where col2=@Variable2Can I write it as above and how would I assign each of the variables the 2 values.Thanks!!SA |
 |
|
|
cat_jesus
Aged Yak Warrior
547 Posts |
Posted - 2009-09-01 : 22:31:52
|
That really depends on how you are running the SQL. If you're using SSMS and the variables are varchar(10) then it would bedeclare @Variable1 as varchar(10)declare @Variable2 as varchar(10)select @Variable1 = 'something'select @Variable2 = 'or_another'insert into table1 (col1, col2, col3, col4)select @Variable1, col2, col3, col4from table2where col2=@Variable2 An infinite universe is the ultimate cartesian product. |
 |
|
|
|
|
|
|
|