Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using INSERT to insert data into multiple rows

Posted on 2006-06-09
4
Medium Priority
?
423 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 500 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

618 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