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 |
|
kingroon
Starting Member
29 Posts |
Posted - 2005-12-28 : 00:51:44
|
| Hi,Wondering if anyone can help with this..I want to INSERT some data already SELECTED in a query and also some other variables.. Will the **dodgy code** make it easier to understand I wonder..** DODGY CODE **INSERT INTO tblTableOne(Column1, Column2, Column3, Column4)VALUES( ( SELECT Column1, Column2 FROM tblTableTwo ), "Text for Column3", "And text for column4")** END OF DODGY CODE **I understand it may have something to do with TEMP TABLES perhaps??Any help greatly appreciated..KingRoonChaotician Man,Slice the lines of virgin pathways.Harmony Hero. |
|
|
shallu1_gupta
Constraint Violating Yak Guru
394 Posts |
Posted - 2005-12-28 : 00:58:38
|
| I think this is what you are looking forINSERT INTO tblTableOne(Column1, Column2, Column3, Column4)SELECT Column1, Column2 , '<Text for Column3>', '<And text for column4'>"FROM tblTableTwo |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-12-28 : 01:20:12
|
| Also look for INSERT...SELECT in Books On Line, SQL Server help fileMadhivananFailing to plan is Planning to fail |
 |
|
|
kingroon
Starting Member
29 Posts |
Posted - 2005-12-28 : 17:50:59
|
| Thanks so much shallu1_gupta,Would it be possible to then concatenate two of the SELECTed results? So that for example the combined [concat.] values of SELECTed Column1 and Column2 are inserted into Column12? Once again employing dodgy code..** MORE DODGY CODE **INSERT INTO tblTableOne(Column12, Column3, Column4)SELECT Column1, Column2 , '<Text for Column3>', '<And text for column4'>"FROM tblTableTwo** END OF MORE DODGY CODE **It seems that the number of SELECT columns out numbers the number of INSERT columns, and would hence error.Thanks,KingRoonChaotician Man,Slice the lines of virgin pathways.Harmony Hero. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-12-28 : 17:56:37
|
| INSERT INTO tblTableOne(Column12, Column3, Column4)SELECT Column1, Column2 , Column1 + Column2, Column2 + Column1FROM tblTableTwoIf you can write a SELECT that outputs what you want inserted into your table, then you can do it. To concatenate columns in T-SQL, you use +.Tara Kizeraka tduggan |
 |
|
|
|
|
|
|
|