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.
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 pmselect * from hospitalPatientID AdmissionDate DischargeDate Cost709 2011-07-27 00:00:00.000 2011-07-31 00:00:00.000 450.00709 2011-08-01 00:00:00.000 2011-08-23 00:00:00.000 2070.00709 2011-08-31 00:00:00.000 2011-08-31 00:00:00.000 90.00709 2011-09-01 00:00:00.000 2011-09-14 00:00:00.000 1260.00709 2011-12-01 00:00:00.000 2011-12-31 00:00:00.000 2790.001624 2011-06-07 00:00:00.000 2011-06-28 00:00:00.000 1980.001624 2011-06-29 00:00:00.000 2011-07-31 00:00:00.000 2970.001624 2011-08-01 00:00:00.000 2011-08-02 00:00:00.000 180.001000 2013-03-14 18:10:25.687 2013-03-15 12:10:25.687 1000.001001 2013-03-14 18:10:40.280 2013-03-15 12:10:40.280 2000.00so 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 Cost1000 2013-03-14 18:10:25.687 2013-03-15 12:10:25.687 1000.001001 2013-03-14 18:10:40.280 2013-03-15 12:10:40.280 2000.00ThanksRajan |
|
|
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 select709,'2011-07-27 00:00:00.000','2011-07-31 00:00:00.000',450.00 union all select709,'2011-08-01 00:00:00.000','2011-08-23 00:00:00.000',2070.00 union all select709,'2011-08-31 00:00:00.000','2011-08-31 00:00:00.000',90.00 union all select709,'2011-09-01 00:00:00.000','2011-09-14 00:00:00.000',1260.00 union all select709,'2011-12-01 00:00:00.000','2011-12-31 00:00:00.000',2790.00 union all select1624,'2011-06-07 00:00:00.000','2011-06-28 00:00:00.000',1980.00 union all select1624,'2011-06-29 00:00:00.000','2011-07-31 00:00:00.000',2970.00 union all select1624,'2011-08-01 00:00:00.000','2011-08-02 00:00:00.000',180.00 union all select1000,'2013-03-14 18:10:25.687','2013-03-15 12:10:25.687',1000.00 union all select1001,'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] |
|
|
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 MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|