Posted on 2011-10-05
Last Modified: 2012-05-12
Hi, how to insert more rows with 1 sql statement?

For example i have 2 columns

Cloumn1, Column2
1               A    
2               B

Question by:hrvica5
    LVL 15

    Expert Comment

    insert into tablename (Cloumn1, Column2)
    select sourcefield1, sourcefield2 from sourcetable
    LVL 9

    Expert Comment

    INSERT INTO tblName
    SELECT 1, 'A'
    SELECT 2, 'B'

    LVL 142

    Accepted Solution

    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


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    I recently came across an interesting Question In EE ( and was puzzled about how to achieve that using SSIS out of the box tasks, which was i…
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
    This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

    755 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

    19 Experts available now in Live!

    Get 1:1 Help Now