mercwrought
Programmer
Hi all are you ready for some of the ugliest code that you have ever seen?
I need to re write this code but I can not figure out how to do it. Originally this code was just used so I could move on and finish the rest of the sp and now I optimizing it.
Thank you for any suggestions and help.
As you can see f in #whatever needs to be set to 1 if there are any records in focompdaily that have the same id number, and confirmation in #whatever and the transaction date or posting date fall between #whatever arrival date and departure date.
I need to re write this code but I can not figure out how to do it. Originally this code was just used so I could move on and finish the rest of the sp and now I optimizing it.
Thank you for any suggestions and help.
Code:
update s1
set f= (Case when(SELECT COUNT(*)
FROM focompdaily
WHERE ConfirmationNumber=s1.confirmation AND idnumber=s1.idnumber
AND ((transactiondate BETWEEN s1.arrivaldate AND s1.departuredate)
OR (postingdate BETWEEN s1.arrivaldate AND s1.departuredate))
AND revenuecenter='RMS' AND comptype IN ('RC','RF','FB','FC') )>0 then 1
else 0 end)
from #whatever s1