Author |
Topic |
chbala85
Starting Member
49 Posts |
Posted - 2014-04-15 : 07:22:55
|
Hi AllNumber patientid AdmissionDate DischargeDate1 35 2014-02-15 2014-03-20 2 35 2014-03-26 NULL1 385 2014-02-05 2014-02-10 2 385 2014-04-10 NULLour table data like abovei want to display below recordNumber patientid AdmissionDate DischargeDate1 35 2014-02-15 2014-03-20 2 35 2014-03-26 NULLthe condition is (AdmissionDate-AdmissionDate) < 30(2014-03-26 -2014-03-20) < 30Please help me.......... |
|
ashishashish
Constraint Violating Yak Guru
408 Posts |
Posted - 2014-04-15 : 07:25:02
|
Can you please explain logic?------------------------------------------------The answer is always no till than you don't ask. |
|
|
VeeranjaneyuluAnnapureddy
Posting Yak Master
169 Posts |
Posted - 2014-04-15 : 07:39:38
|
DECLARE @Table TABLE(Number INT,patientid INT,AdmissionDate DATE,DischargeDate VARCHAR(11))INSERT INTO @Table VALUES(1,35,'2014-02-15','2014-03-20'),(2,35,'2014-03-26','NULL'),(1,385,'2014-02-05','2014-02-10'),(2,385,'2014-04-10','NULL')SELECT * FROM @Table WHERE DATEPART(DAY,-DATEPART(DAY,AdmissionDate)) < 30Veera |
|
|
chbala85
Starting Member
49 Posts |
Posted - 2014-04-15 : 08:17:28
|
Hi AllNumber patientid AdmissionDate DischargeDate1 35 2014-02-15 2014-03-20 2 35 2014-03-26 NULL1 385 2014-02-05 2014-02-10 2 385 2014-04-10 NULL1 40 2014-04-15 NULLour table data like aboveThe condition is (AdmissionDate-AdmissionDate) < 30(2014-03-26 -2014-03-20) < 30conditions:-1)To find any patients having more than one record,if you find2) (same patients second admissiondate - same patients dischargedate) < 30i want output like below:Number patientid AdmissionDate DischargeDate1 35 2014-02-15 2014-03-20 2 35 2014-03-26 NULL |
|
|
VeeranjaneyuluAnnapureddy
Posting Yak Master
169 Posts |
Posted - 2014-04-15 : 08:52:06
|
DECLARE @Table TABLE(Number INT,patientid INT,AdmissionDate DATE,DischargeDate VARCHAR(11))INSERT INTO @Table VALUES(1,35,'2014-02-15','2014-03-20'),(2,35,'2014-03-26',NULL),(1,385,'2014-02-05','2014-02-10'),(2,385,'2014-04-10',NULL)SELECT TOP 2 * FROM @Table WHERE DATEPART(DAY,-DATEPART(DAY,AdmissionDate)) < 30 AND (DATEPART(DAY,-DATEPART(DAY,AdmissionDate)) - DATEPART(DAY,-DATEPART(DAY,ISNULL(DischargeDate,'1900-01-01')))) < 30 Veera |
|
|
|
|
|