Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert help 1

Status
Not open for further replies.

onressy

Programmer
Mar 7, 2006
421
CA
Hi, I have a table that has the following columns:
surveyid = int,
memberid = int
started = int
StartedOnDate = samllDateTime
Completed = int

I would like to copy the records from memberID 2215 to memberID 1323 where surveyID in 2215 does not exist where memberID=1323. any thoughts on how to do this?

Thanks
 
This will duplicate the record.
Code:
insert into table
(surveyid, memberid, started, StartedOnDate, Completed)
select surveyid, 1323, started, StartedOnDate, Completed
where surveyID = 2215 and memberid = 2215
This assumes that proper unique indexes and / or primary keys are setup. If surveyid 2215 for member 1323 already exists a primary key / unique index violation will occure if proper key / index is setup.

Denny
MCSA (2003) / MCDBA (SQL 2000) / MCTS (SQL 2005) / MCITP Database Administrator (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
cheers mrdenny and thanks for the heads up on key violations,

wishing you a great day!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top