• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

SQL

Hi, how to insert more rows with 1 sql statement?

For example i have 2 columns

Cloumn1, Column2
1               A    
2               B

Thx  
0
hrvica5
Asked:
hrvica5
1 Solution
 
EyalCommented:
insert into tablename (Cloumn1, Column2)
select sourcefield1, sourcefield2 from sourcetable
0
 
s_chilkuryCommented:
INSERT INTO tblName
SELECT 1, 'A'
UNION ALL
SELECT 2, 'B'

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
where does the data come from?
if it comes from a table: see above comment

otherwise, you may do this:

insert into tablename ( column1, column2) select 1, 'A' union all select 2,'B' 

Open in new window


if you have the very recent version of sql server 2008 R2, you could also do:
insert into tablename ( column1, column2) values ( 1, 'A' ), (2,'B' ) 

Open in new window


0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now