Solved

Using INSERT to insert data into multiple rows

Posted on 2006-06-09
4
420 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 143

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

697 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