Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Babaella
Starting Member
3 Posts |
Posted - 2011-08-22 : 10:21:35
|
| Hi I have a data base that has a unique patient id, a row id that corresponds to each episode of care a patient has (they can have more than 1 row per admission), a date of admission to hospital and a date of discharge. there is also an field that shows the order of the episode of care, however this may not start at 1 as the patient may have been admitted prior to the time period I am looking at.I want to be able to flag whether an individual was readmitted within 30 days of a previous admission (ie there admission date is within 30 days of the previous discharge date).I have tried UPDATE A SET A.prioradmission30days = 1 from HES_Working.dbo.AC_GG_BroadAge_FCEs0809 A WHERE EXISTS ( SELECT * from HES_Working.dbo.AC_GG_BroadAge_FCEs0809 B WHERE (A.hesid = B.hesid) AND (A.RowID = B.RowID) AND (DATEDIFF(DAY, B.dischargedate, A.admidate) BETWEEN 30 AND 0)however this does not update any records (I know there are some readmissions within 30 days as 1 patient had 320 admissions in a year).any help would be most appreciatedbaba |
|
|
sqlnovice1
Starting Member
34 Posts |
Posted - 2011-08-22 : 11:14:02
|
| Hi I actually work for the NHS and supply the SUS data which I presume your HES table is looking at. I have recently set up the same query.you need to do a self join on your admissions table where the hesid = the hesid and the attendance = attendance - 1. then compare the admission and diachrge dates/time from each Thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-22 : 12:06:51
|
something like UPDATE A SET A.prioradmission30days = 1 from HES_Working.dbo.AC_GG_BroadAge_FCEs0809 ACROSS APPLY (SELECT TOP 1 dischargedate FROM HES_Working.dbo.AC_GG_BroadAge_FCEs0809 hesid = A.hesid AND dischargedate < A.admidate ORDER BY dischargedate DESC) BWHERE A.admidate<= DATEADD(dd,30,dischargedate) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Babaella
Starting Member
3 Posts |
Posted - 2011-08-22 : 12:54:10
|
| thankyou so much for your help - I am trying the second suggestion but won't get an answer until the morning as the data set is massive!Baba |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-22 : 13:08:39
|
| ok no probs..let us know how you got on!------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Babaella
Starting Member
3 Posts |
Posted - 2011-08-23 : 11:40:56
|
| HiIT has worked perfectly! thankyou so much for your help. Baba |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-23 : 12:01:30
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|