Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


multi insert

Posted on 2006-05-31
Medium Priority
Last Modified: 2012-05-05
Have 65 rows of the same email_id (email1) but with different values in admin_id and all GMFlag equal to 1. I need the same duplicate rows set up for email2 and email3.

email_id  admin_id  GMFlag
email1    6                   1
email1    7              1

email1    6                   1
email1    7              1
email2    6              1
email2    7              1
email3    6              1
email3    7              1

Insert into databasename..tablename (email_id, admin_id, GMFlag)
select ('email2', 6, 1)
union all select ('email2', 7, 1)
union all select ('email3', 6, 1)
union all select ('email3', 7, 1)

I'm not sure if the above is correct. How do I acheive this?

Question by:fwsteal
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 16800018
Insert into databasename..tablename (email_id, admin_id, GMFlag)
select 'email2', 6, 1
union all select 'email2', 7, 1
union all select 'email3', 6, 1
union all select 'email3', 7, 1
LVL 34

Accepted Solution

Brian Crowe earned 2000 total points
ID: 16800113
INSERT INTO databasename..tablename (email_id, admin_id, GMFlag)
SELECT 'email2', admin_id, GMFlag
FROM databasename..tablename
WHERE email_id = 'email1'

then run it a second time changing 'email2' to 'email3'

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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…
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Suggested Courses

578 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