Solved

Using INSERT to insert data into multiple rows

Posted on 2006-06-09
4
411 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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

771 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

12 Experts available now in Live!

Get 1:1 Help Now