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
 General SQL Server Forums
 New to SQL Server Programming
 Need Query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Paramasivan B
Starting Member

India
4 Posts

Posted - 03/15/2013 :  02:00:55  Show Profile  Reply with Quote


Hi All
How to write a query for retrieving the data from yesterday 6pm to still



Paramasivan B

RajanThan
Starting Member

India
7 Posts

Posted - 03/15/2013 :  02:49:39  Show Profile  Reply with Quote
The patient id 1000 and 1001 are admitted on yesterday after 6 pm

select * from hospital
PatientID AdmissionDate DischargeDate Cost
709 2011-07-27 00:00:00.000 2011-07-31 00:00:00.000 450.00
709 2011-08-01 00:00:00.000 2011-08-23 00:00:00.000 2070.00
709 2011-08-31 00:00:00.000 2011-08-31 00:00:00.000 90.00
709 2011-09-01 00:00:00.000 2011-09-14 00:00:00.000 1260.00
709 2011-12-01 00:00:00.000 2011-12-31 00:00:00.000 2790.00
1624 2011-06-07 00:00:00.000 2011-06-28 00:00:00.000 1980.00
1624 2011-06-29 00:00:00.000 2011-07-31 00:00:00.000 2970.00
1624 2011-08-01 00:00:00.000 2011-08-02 00:00:00.000 180.00
1000 2013-03-14 18:10:25.687 2013-03-15 12:10:25.687 1000.00
1001 2013-03-14 18:10:40.280 2013-03-15 12:10:40.280 2000.00

so write the following query to retrieve the data after 6 pm,

select * from Hospital where AdmissionDate >= '2013-03-14 18:00:00.000'
Answer:
PatientID AdmissionDate DischargeDate Cost
1000 2013-03-14 18:10:25.687 2013-03-15 12:10:25.687 1000.00
1001 2013-03-14 18:10:40.280 2013-03-15 12:10:40.280 2000.00

Thanks

Rajan
Go to Top of Page

waterduck
Aged Yak Warrior

Malaysia
965 Posts

Posted - 03/15/2013 :  06:30:25  Show Profile  Reply with Quote
declare @hospital table(PatientID int,AdmissionDate datetime,DischargeDate datetime,Cost numeric(10,2))
insert into @hospital select
709,'2011-07-27 00:00:00.000','2011-07-31 00:00:00.000',450.00 union all select
709,'2011-08-01 00:00:00.000','2011-08-23 00:00:00.000',2070.00 union all select
709,'2011-08-31 00:00:00.000','2011-08-31 00:00:00.000',90.00 union all select
709,'2011-09-01 00:00:00.000','2011-09-14 00:00:00.000',1260.00 union all select
709,'2011-12-01 00:00:00.000','2011-12-31 00:00:00.000',2790.00 union all select
1624,'2011-06-07 00:00:00.000','2011-06-28 00:00:00.000',1980.00 union all select
1624,'2011-06-29 00:00:00.000','2011-07-31 00:00:00.000',2970.00 union all select
1624,'2011-08-01 00:00:00.000','2011-08-02 00:00:00.000',180.00 union all select
1000,'2013-03-14 18:10:25.687','2013-03-15 12:10:25.687',1000.00 union all select
1001,'2013-03-14 18:10:40.280','2013-03-15 12:10:40.280',2000.00;
select * from @hospital where AdmissionDate > DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()) - 1 , 0) + 0.75
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 03/15/2013 :  11:30:38  Show Profile  Reply with Quote
select * from @hospital where AdmissionDate >= dateadd(dd,datediff(dd,0,getdate())-0.25,0)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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.06 seconds. Powered By: Snitz Forums 2000