MdotButler
Programmer
I am looking for a bit of help creating a SQL update statement. The task is to update a first and last activity date in a company table based on bills that are going through a billing cycle. The following code would update the entire company table and is what I used when I created the new activity date fields. It process all companies and all encounters.
Now the twist is to only update the companies in the current batch of bills and only if the activity dates are less than or greater than the activity values already in the company table. There is a field in the encounter (EN_BilledBATID) containing a batch id and the procedure has a variable (@BATID) containing the batch id we are currently processing.
I thought about doing this with a cursor and looping through for each company being processed in the current batch but I would like to do it without looping through a cursor.
Any help would be appreciated. thanx
Mark
Code:
UPDATE Company Set
C_FirstActivity = (SELECT MIN(EN_AddDate) FROM Encounter WHERE EN_CID = C_CID),
C_LastActivity = (SELECT MAX(EN_AddDate) FROM Encounter WHERE EN_CID = C_CID)
I thought about doing this with a cursor and looping through for each company being processed in the current batch but I would like to do it without looping through a cursor.
Any help would be appreciated. thanx
Mark