Solved

Using INSERT to insert data into multiple rows

Posted on 2006-06-09
4
416 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

773 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