SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 urgent help needed..plz help me
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vasu123
Starting Member

1 Posts

Posted - 05/07/2014 :  19:08:34  Show Profile  Reply with Quote
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)

Singapore
17584 Posts

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

what do you mean by that ?


KH
Time is always against us

Go to Top of Page

denis_the_thief
Aged Yak Warrior

Canada
591 Posts

Posted - 05/08/2014 :  11:13:01  Show Profile  Reply with Quote
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

571 Posts

Posted - 05/08/2014 :  11:48:42  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000