Solved

Using INSERT to insert data into multiple rows

Posted on 2006-06-09
4
415 Views
Last Modified: 2012-08-14
I am pretty sure this would work in MySQL, but I can verify that it does not in MS SQL. Here is a sample of what I am trying to do, and failing at. What would the correct way be?


INSERT INTO assets
                      (id_assets, employee_assets, pcname_assets, serial_assets, model_assets)
VALUES    
(DEFAULT,'belinda samuels', 'spl-atl-l651', 'l3-aw023', 'IBM ThinkPad t42'),
(DEFAULT,'Arlene Sia', 'spl-atl-l965', 'l3-af830', 'IBM ThinkPad t42')
(DEFAULT,'Joy Morrison', 'spl-atl-l979', 'L3-ad717', 'IBM ThinkPad T42')
0
Comment
Question by:kwestion
4 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 16870059

INSERT INTO assets
                      (employee_assets, pcname_assets, serial_assets, model_assets)
SELECT 'belinda samuels', 'spl-atl-l651', 'l3-aw023', 'IBM ThinkPad t42'
UNION ALL SELECT 'Arlene Sia', 'spl-atl-l965', 'l3-af830', 'IBM ThinkPad t42'
UNION ALL SELECT 'Joy Morrison', 'spl-atl-l979', 'L3-ad717', 'IBM ThinkPad T42'
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 16870127
like angelii specified although i though you needed to
name the columns on the first select...

INSERT INTO assets
                      (employee_assets, pcname_assets, serial_assets, model_assets)
SELECT 'belinda samuels' as asset, 'spl-atl-l651' as pcname, 'l3-aw023' as serialasset, 'IBM ThinkPad t42' as model
UNION ALL SELECT 'Arlene Sia', 'spl-atl-l965', 'l3-af830', 'IBM ThinkPad t42'
UNION ALL SELECT 'Joy Morrison', 'spl-atl-l979', 'L3-ad717', 'IBM ThinkPad T42'
0
 
LVL 13

Expert Comment

by:Atlanta_Mike
ID: 16870269
Or...

INSERT INTO assets   (id_assets, employee_assets, pcname_assets, serial_assets, model_assets)
VALUES  (DEFAULT,'belinda samuels', 'spl-atl-l651', 'l3-aw023', 'IBM ThinkPad t42'),
INSERT INTO assets   (id_assets, employee_assets, pcname_assets, serial_assets, model_assets)
VALUES  (DEFAULT,'Arlene Sia', 'spl-atl-l965', 'l3-af830', 'IBM ThinkPad t42')
INSERT INTO assets   (id_assets, employee_assets, pcname_assets, serial_assets, model_assets)
VALUES  (DEFAULT,'Joy Morrison', 'spl-atl-l979', 'L3-ad717', 'IBM ThinkPad T42')
0
 

Author Comment

by:kwestion
ID: 16870792
angels worked. It added a little code to it automatically, something similar to lowfatspreads comment. it added as expression# to the values, but it worked!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now