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
 Transact-SQL (2000)
 Duplicate Data inserting through INSERT

Author  Topic 

daipayan
Posting Yak Master

181 Posts

Posted - 2009-08-13 : 07:32:12
Respected Coders,
I have the following INSERT statement:
INSERT INTO dbo.attendence_date (course_code, attendence_time, attendence_date)
SELECT i.monday as D_day, i.routine_time, rd.routine_date_from
FROM dbo.routine_date rd INNER JOIN
dbo.routine_details i ON rd.routine_ID = i.routine_ID
where i.monday != 'Free'

Whenever I am firing the following INSERT statement, new data as well as the old data is again being inserted in the attendence_date table.
Can you tell me, how to avoid inserting duplicate data in the attendence_date by firing the following INSERT STATEMENT!
Please am in great need..PLEASE HELP!!

Daipayan

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-08-13 : 07:54:58
use distinct keyword or

INSERT INTO dbo.attendence_date (course_code, attendence_time, attendence_date)
SELECT i.monday as D_day, i.routine_time, rd.routine_date_from
FROM dbo.routine_date rd INNER JOIN
dbo.routine_details i ON rd.routine_ID = i.routine_ID
left join attendence_date d on d.course_code = i.monday and i.routine_time = d.attendence_time
and d.attendence_Date = rd.routine_date_from
where i.monday != 'Free' and d.course_code is null
Go to Top of Page
   

- Advertisement -