Posted by: arnzombie May 29, 2008
SQL UPDATE help
Login in to Rate this Post:     0       ?        

I am still not sure what result you are expecting. But Again dont use EXISTS for it does not FILTER anything.

Maybe this can help a little bit:

-------------------------------------------------------------------------------------------

STEP 1 to insert into TABLE_B

INSERT INTO TABLE_B (

SELECT .... FROM TABLE_A

LEFT OUTER JOIN TBL1

LEFT OUTER JOIN TBL2

a.ExpDate between dateadd(mm,2,getdate()) AND dateadd(mm,7,getdate())

-------------------------------------------------------------------------------------------

STEP 2:

UPDATE TABLE_A --- OR TABLE_B as needed

SET status='1st Notice'

WHERE table_a.id in (SELECT .... FROM TABLEA,Tbl1,Tbl2  WHERE......)

AND a.ExpDate >= dateadd(mm,2,getdate())

AND a.ExpDate<=dateadd(mm,2,getdate())+7

AND status in NULL ; -- OR '1st Status 'as required.

--------------------------------------------------------------------------------------------------

Also Note that if you are using procedure i suggest you to us IF..ELSE clause.

sorry syntax is in oracle standard

IF status = NULL THEN

......update table_a set status='1st Notice'..........

ELSIF status ='1st Notice' THEN

...........update table_a set status='2nd Notice'..........

End IF;

------------------------------------------------------------------------------------------------------------

I hope this would be helpful for you.

If not dont stress try to forget this for a while...RELAX....And get back with fresh mind you will get this done easily. GOOD LUCK

Read Full Discussion Thread for this article