Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Inser into a table with primary key

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2006-07-10 : 12:16:06
I setup a job to run at midnight everday as bellow

truncate table myTableOrder
Insert into myTableOrder select * from myViewOrder

myTableOrder has a primary in OrderID.

Problem is: if myViewOrder has duplicate OrderID, job will fail.

How to void it so that job will run until end?

nr
SQLTeam MVY

12543 Posts

Posted - 2006-07-10 : 12:20:44
Make sure that the OrderID in myViewOrder is unique.
you can

Insert into myTableOrder
select * from myViewOrder
where OrderID not in (select OrderID from myViewOrder group by OrderID having count(*) > 1)

but you should fix the source.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -