November 30, 2008 at 11:11 pm
I ran an Insert script:
insert into tableA (column1, column2)
values( select column1 from tableB ,select column2 from tableC)
Isnt this valid in SQL Server 2005?
November 30, 2008 at 11:27 pm
Well syntactically, you want something like this:
insert into tableA (column1, column2)
values(
(select column1 from tableB)
,(select column2 from tableC)
)
This is valid syntax, however, the logic of this looks pretty suspect.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
December 1, 2008 at 12:07 am
Does'nt seem to work.
"Keep Trying"
December 1, 2008 at 1:12 am
That statement wont work.. ...
You can insert using this statement
Insert into tablesa(column1, column2)
select column1, column2 from tableb
The select statement can return many records... all records will be inserted in to the table(tablea).
Just check and let me know.
December 1, 2008 at 2:52 am
Hi,
rbarryyoung's code is not working.
Gouthama's code is working, but it is not effective from the context because actually its trying to insert from two tables.
I guess, we need to use JOIN between tableB and tableC.
December 1, 2008 at 3:15 am
Absolutely YES.. you need to use inner join if you want to insert values from different tables.
The result set which you will get in the select statement... same records will be inserted in to the table which you want to insert.
December 1, 2008 at 6:40 am
Oops, you folks are right, my bad. That's what I get for posting at 2AM...
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply