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
 Need Query

Author  Topic 

Paramasivan B
Starting Member

5 Posts

Posted - 2013-03-15 : 02:00:55


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



Paramasivan B

RajanThan
Starting Member

7 Posts

Posted - 2013-03-15 : 02:49:39
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

982 Posts

Posted - 2013-03-15 : 06:30:25
[code]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[/code]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-15 : 11:30:38
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
   

- Advertisement -