ichiyo85 (1/31/2011)
Hi, on a similar note, I want to make a stored procedure where I can delete customers from a December customer table, but only those who will show up again in January. Keep those who are not returning, and insert the existing and new customers from January. In other word, I am trying to update a customer table every month by deleting the old and replace/insert the new.Something like:
delete from AccountMaster
where AccountMaster.AccountID in (select AccountID from RevDec2010)
insert into AccountMaster (AccountID,Period)
select distinct AccountID, Period
from RevJan2011
How can I declare the table object "RevDec2010" and so forth in the stored procedure?
Thank you very very much in advance!!
Hi,
When ever you are posting staert in new post
If you are using SQL 2008 there is concept called MERGE is there, where u will be able to INSERT,UPDATE,DELETE on conditions.(If you are using 2005 ignore this just want to say there is a opition is there in 2008)
http://msdn.microsoft.com/en-us/library/bb510625.aspx
For upcoming data you need to check whether it EXISTS or not in the table if EXISTS you need to UPDATE the record or DELETE and INSERT the new record.Hints
you can use
1)EXISTS
2)NOT EXISTS
3)@Flag
4)MERGE--2008
etc...
There are so many options are there i have given only 1 or 2 there are lot of options are there try with your own and come back with your code if you are not able to get the solution
Thanks
Parthi
Thanks
Parthi