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
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 urgent help needed..plz help me

Author  Topic 

vasu123
Starting Member

1 Post

Posted - 2014-05-07 : 19:08:34
Hi everyone..


I got patient_table columns [patnt_no],[patnt_refno] ,[admit_date],[discharge_date] ,[hospital_branch]
i just want retrieve patient information from 1st discharge date to 6 months later date .


patnt_no patnt_refno admit_date discharge_date
2342 5623 2010-05-07 12:00:00.000 2010-06-19 18:00:00.000
2342 3562 2010-07-21 14:25:00.000 2010-09-25 07:55:16.000
2342 7856 2010-11-15 00:00:00.000 2013-01-01 00:00:00.000
4261 9567 2011-03-16 00:00:00.000 2011-05-26 12:00:00.000
4261 7589 2014-04-15 00:00:00.000 2014-05-30 15:00:45.000
7689 1254 2012-03-16 13:15:00.000 2012-04-28 16:00:00.000
7689 4521 2012-07-14 15:00:00.000 2012-09-11 18:00:00.000
7689 2642 2012-09-15 14:00:00.000 2014-04-13 16:00:00.000
5621 2323 2012-10-12 13:00:15.000 2014-04-23 19:00:00.000
5621 2423 2014-04-28 19:00:00.000 2014-05-05 16:00:00.000
I want format like this
2342 3562 2010-07-21 14:25:00.000 2010-09-25 07:55:16.000
7689 4521 2012-07-14 15:00:00.000 2012-09-11 18:00:00.000
5621 2423 2014-04-28 19:00:00.000 2014-05-05 16:00:00.000

Thanks in advance..

vas

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-05-08 : 02:23:15
quote:
i just want retrieve patient information from 1st discharge date to 6 months later date .

what do you mean by that ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

denis_the_thief
Aged Yak Warrior

596 Posts

Posted - 2014-05-08 : 11:13:01
Getting help on a discussion board for medical software?

Scary, no wonder why they mixed up my blood test results.
Go to Top of Page

Ifor
Aged Yak Warrior

700 Posts

Posted - 2014-05-08 : 11:48:42
Maybe something like:

-- *** Test Data ***
CREATE TABLE #t
(
patnt_no int NOT NULL
,patnt_refno int NOT NULL
,admit_date datetime NOT NULL
,discharge_date datetime NOT NULL
);
INSERT INTO #t
VALUES (2342, 5623, '20100507 12:00:00.000', '20100619 18:00:00.000')
,(2342, 3562, '20100721 14:25:00.000', '20100925 07:55:16.000')
,(2342, 7856, '20101115 00:00:00.000', '20130101 00:00:00.000')
,(4261, 9567, '20110316 00:00:00.000', '20110526 12:00:00.000')
,(4261, 7589, '20140415 00:00:00.000', '20140530 15:00:45.000')
,(7689, 1254, '20120316 13:15:00.000', '20120428 16:00:00.000')
,(7689, 4521, '20120714 15:00:00.000', '20120911 18:00:00.000')
,(7689, 2642, '20120915 14:00:00.000', '20140413 16:00:00.000')
,(5621, 2323, '20121012 13:00:15.000', '20140423 19:00:00.000')
,(5621, 2423, '20140428 19:00:00.000', '20140505 16:00:00.000');
-- *** End Test Data ***

SELECT *
FROM #t T1
WHERE EXISTS
(
SELECT 1
FROM #t T2
WHERE T2.patnt_no = T1.patnt_no
AND T2.discharge_date < T1.discharge_date
AND T2.discharge_date >= DATEADD(month, -6, T1.discharge_date)
);

Go to Top of Page
   

- Advertisement -