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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query required

Author  Topic 

chbala85
Starting Member

49 Posts

Posted - 2014-04-15 : 07:22:55
Hi All

Number patientid AdmissionDate DischargeDate
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

our table data like above

i want to display below record

Number patientid AdmissionDate DischargeDate
1 35 2014-02-15 2014-03-20
2 35 2014-03-26 NULL


the condition is (AdmissionDate-AdmissionDate) < 30

(2014-03-26 -2014-03-20) < 30


Please 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.
Go to Top of Page

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)) < 30


Veera
Go to Top of Page

chbala85
Starting Member

49 Posts

Posted - 2014-04-15 : 08:17:28
Hi All

Number patientid AdmissionDate DischargeDate
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
1 40 2014-04-15 NULL

our table data like above



The condition is (AdmissionDate-AdmissionDate) < 30

(2014-03-26 -2014-03-20) < 30

conditions:-
1)To find any patients having more than one record,if you find
2) (same patients second admissiondate - same patients dischargedate) < 30

i want output like below:

Number patientid AdmissionDate DischargeDate
1 35 2014-02-15 2014-03-20
2 35 2014-03-26 NULL

Go to Top of Page

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
Go to Top of Page
   

- Advertisement -