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
 Sql To pull Appt Dates 2 Days Greater than Current

Author  Topic 

LOgle0917
Starting Member

9 Posts

Posted - 2008-02-04 : 14:08:51
I am pulling data that shows appt information on a patient:

FName,LName, PhoneNumber, ApptDate, ApptTime, and Status that equals Active. I need to pull this info everyday. How can I set this up in a stored procedure to pull all this information automatically on a daily basis where it pulls by Appt Date that is 2 days greater than the current date?

Thanks!

Thanks!
Lisa

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2008-02-04 : 14:14:29
SELECT FName,Lname ,PhoneNumber, ApptDate, ApptTime FROM myTable
WHERE Status= 'Active' and ApptDate > getDate() + 2

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-02-04 : 14:19:44
SELECT FName,LName, PhoneNumber, ApptDate, ApptTime
FROM yourTable
WHERE DATEDIFF(day,current_timestamp,apptdate) = 2
and Status = 'Active'


Jim

P.S Now explain to you professor the difference between the two!
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-02-04 : 17:12:51
This is usually best to code these queries as a range, instead of running the table column through a function. If you use a function on a column, it will prevent use of an index on AppDate

select
FName,
Lname,
PhoneNumber,
ApptDate,
ApptTime
from
myTable
where
Status= 'Active' and
ApptDate >= dateadd(day,datediff(day,0,getDate())+2,0) and
ApptDate < dateadd(day,datediff(day,0,getDate())+3,0)




CODO ERGO SUM
Go to Top of Page

LOgle0917
Starting Member

9 Posts

Posted - 2008-02-05 : 09:24:12
I have two tables that this information is pulling from. One is the Patient Table and one is the ApptHis Table. My fields in the ApptHis table are date and time when I try using these fields my fields turn blue, how can I correct this? Thanks!

Thanks!
Lisa
Go to Top of Page

LOgle0917
Starting Member

9 Posts

Posted - 2008-02-05 : 09:29:27
Here is what I am trying to use it is an oracle database:

SELECT
Patient.PatientFirst,
Patient.PatientLast,
Patient.PatientHomeArea,
Patient.PatientHomePhone,
Patient.PatientStatus,
ApptHis.AppHistDate,
ApptHis.AppHistTime
From
Patient, ApptHis
Where
Status= 'Active' and
ApptHis.ApptHisDate >= dateadd(day,datediff(day,0,getDate())+2,0) and
ApptHis.ApptHisDate < dateadd(day,datediff(day,0,getDate())+3,0)

Thanks!
Lisa
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-02-05 : 09:45:02
quote:
Originally posted by LOgle0917
...it is an oracle database...


That changes things.



CODO ERGO SUM
Go to Top of Page

LOgle0917
Starting Member

9 Posts

Posted - 2008-02-05 : 15:11:42
I apologize as I guess I am asking my question in the wrong place. I am using Toad to pull the information and it is supposed to use SQL Scripting to pull the information. The client is an oracle client so I am confused on how to do this. I thought that SQL could be used but if the client is Oracle you have to use a little different programming. Sorry. I will look elsewhere for assistance.

Thanks!
Lisa
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-06 : 01:04:45
Try at www.orafaq.com or www.dbforums.com

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

LOgle0917
Starting Member

9 Posts

Posted - 2008-02-06 : 09:18:29
Thank you!

Thanks!
Lisa
Go to Top of Page
   

- Advertisement -