In need of your help again please.
I am trying to repair a database where there are records missing from a table.
I am getting the missing records field values from another table but I need the values to be unique as I cannot add a record that the primary field has already been added. This is the code I am using:
Set Identity_Insert [Tbl_Schedule] On
Insert into Tbl_Schedule(ScheduleID,AssetID,ScheduledDate)
select DISTINCT ScheduleID,AssetID,ScheduledDate from Tbl_WorkOrder
where YEAR(Tbl_WorkOrder.ScheduledDate) = '2017' AND Tbl_WorkOrder.ScheduleID not in(select Tbl_Schedule.ScheduleID from Tbl_Schedule)
Set Identity_Insert [Tbl_Schedule] Off
I need Tbl_WorkOrder.ScheduleID to be unique. At the moment the first select statement is coming back with duplicate scheduleId's
How can I get unique scheduleId's for my first select statement?
Thanks for the help.