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 2005 Forums
 Transact-SQL (2005)
 duplicate records

Author  Topic 

attman
Starting Member

16 Posts

Posted - 2010-01-28 : 11:52:19
-----

insert into tuketimler2 (Title, carpan , serino, ilce, tmID,
ILK_OKUMA_TAR, SON_OKUMA_TAR, TT_ILK_ENDEKS, TT_SON_ENDEKS, TT_FARK,
T1_ILK_ENDEKS, T1_SON_ENDEKS, T1_FARK, T2_ILK_ENDEKS, T2_SON_ENDEKS, T2_FARK,
T3_ILK_ENDEKS, T3_SON_ENDEKS, T3_FARK, R_ILK_ENDEKS, R_SON_ENDEKS, R_FARK,
K_ILK_ENDEKS, K_SON_ENDEKS, K_FARK)

SELECT
Say.ID,
Say.Title nvarchar,
Say.carpan as carpan,
Say.ilce,
Say.tmID,
SayB.Tarih AS ILK_OKUMA_TAR,
SayA.Tarih AS SON_OKUMA_TAR,
SayB.AktifArti AS TT_ILK_ENDEKS,
SayA.AktifArti AS TT_SON_ENDEKS,
SayB.AktifT1 AS T1_ILK_ENDEKS,
SayA.AktifT1 AS T1_SON_ENDEKS,
SayB.AktifT2 AS T2_ILK_ENDEKS,
SayA.AktifT2 AS T2_SON_ENDEKS,
SayB.AktifT3 AS T3_ILK_ENDEKS,
SayA.AktifT3 AS T3_SON_ENDEKS,
SayB.ReaktifArti AS R_ILK_ENDEKS,
SayA.ReaktifArti AS R_SON_ENDEKS,
SayB.KapasitifEksi AS K_ILK_ENDEKS,
SayA.KapasitifEksi AS K_SON_ENDEKS,
From
Counters as Say, Records as SayA, Records as SayB


where SayA.SeriNo = Say.SeriNo and SayB.SeriNo = Say.SeriNo
and SayB.Tarih =(select MAX(SayC.Tarih) from Records as SayC where SayC.SeriNo = SayA.SeriNo

and SayC.Tarih < SayA.Tarih )


----------------------------------------------------------------
the above query is executed; records to the table is added
but

the same query is run again; previously inserted records are added again. and are duplicates. whereas only yin records should be added.
recording criteria is the date column.
Date in my language = Tarih

DP978
Constraint Violating Yak Guru

269 Posts

Posted - 2010-01-28 : 12:11:54
SELECT
Say.ID,
Say.Title nvarchar,
Say.carpan as carpan,
Say.ilce,
Say.tmID,
SayB.Tarih AS ILK_OKUMA_TAR,
SayA.Tarih AS SON_OKUMA_TAR,
SayB.AktifArti AS TT_ILK_ENDEKS,
SayA.AktifArti AS TT_SON_ENDEKS,
SayB.AktifT1 AS T1_ILK_ENDEKS,
SayA.AktifT1 AS T1_SON_ENDEKS,
SayB.AktifT2 AS T2_ILK_ENDEKS,
SayA.AktifT2 AS T2_SON_ENDEKS,
SayB.AktifT3 AS T3_ILK_ENDEKS,
SayA.AktifT3 AS T3_SON_ENDEKS,
SayB.ReaktifArti AS R_ILK_ENDEKS,
SayA.ReaktifArti AS R_SON_ENDEKS,
SayB.KapasitifEksi AS K_ILK_ENDEKS,
SayA.KapasitifEksi AS K_SON_ENDEKS,
From
Counters as Say, Records as SayA, Records as SayB


where
Not exists (Select * from tuketimler2 t2 where t2.ID = say.ID)
and SayA.SeriNo = Say.SeriNo and SayB.SeriNo = Say.SeriNo
and SayB.Tarih =(select MAX(SayC.Tarih) from Records as SayC where SayC.SeriNo = SayA.SeriNo

and SayC.Tarih < SayA.Tarih )
Go to Top of Page

attman
Starting Member

16 Posts

Posted - 2010-01-31 : 09:35:20
thanks
Go to Top of Page
   

- Advertisement -