So I ran into a new issue with this script where when I have patients discharged multiple times a day it isn't taking it into consideration since it's keying off ID and DDate and those will match in these instances.
Here is latest edition of cursor...
Dave I got it to work..First time with cursors so took some time but I really appreciate the help..
Here is the snippet I updated to get everything working good.First highlight is a bug I found in some of the @CoversBookingsUntil calculating.Other highlights are the fix for different patients...
So your script did exactly what it should, which is amazing! but I found one more hurdle which is my fault. I've only been showing a subset of the data. If you notice the coversboookinguntil is incorrect on the last entry for episodestart of 1. It is probably using the ddate from the next...
Tamar:
That won't work for this because the bookingdate needs to be within 30 days of a ddate, but then it needs to count it as an appointment only associated with the previous record with an episodestart of 1..
So we have a patient with many discharges and we set an episode start of 1 only on...
Another update on this beast...
So now that I have the desired table from the cursor, i am needing to join on an appointments table and tie the appointments to episodestart records with a "1" but with a few clauses and a count. Here we go...
So for one patient I have this.
ID2 PID PDID DDATE...
Out of a data set of one patient, I'm trying to locate the first date and set it as a value 1 in a new colum(episodestart)
Then I want to go through each row in order and figure out if it's within 30 days of the previous episodestart column record that was a 1 and mark it with a 0.. If it is...
I have all the data to this point in a temp table and I need to add this column to the data set, so I can then get the ordinal # for these events to better analyze it.
The data will change daily, so I just need the method of creating this information in sql when I run the scripts.
Thanks,
I have basic data like this.
and I want to add the column you see out the far right.
Identity ID Contactid Desired Column
1 A 123 1
2 A 124 1
3 A 125...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.