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)
 max date problem

Author  Topic 

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2008-04-07 : 19:34:12
i have a table temp t that is used as a back up of live table .


the table has following fileds( customer,customercardnumber,transactiondate)

i need to insert these fields into another table t1 in such a way that
no duplicate records are inserted .ie after once a table t1 is populated the next time insert statement should insert only the new records that were added to the temp table t but not all records.

i think using max (transactiondate) of both tables can be considered for this . but don know put in code

thanks .please suggest with the code.

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-04-07 : 20:09:33
Do you have to insert one-time or regularly?
Go to Top of Page

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2008-04-07 : 21:42:44
regularly whenever new transaction is done by new customer o r the same customer.

thanks
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-04-07 : 22:07:07
1)create t1 table with same structure and with constraints added.

2)-- Export distinct data
insert into t1( customer,customercardnumber,transactiondate)
select distinct customer,customercardnumber,transactiondate
from #t

3) Create Trigger as:
Create trigger [TR] on #t
after insert
as
begin
insert into t1(customer,customercardnumber,transactiondate)
select distinct customer,customercardnumber,transactiondate
from inserted
end
Go to Top of Page

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2008-04-07 : 23:12:21
thanks
Go to Top of Page
   

- Advertisement -