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
 data for range of date

Author  Topic 

eugz
Posting Yak Master

210 Posts

Posted - 2009-10-07 : 16:19:21
Hi all.
I would like to create select that display me range of the date from current date to last previuos month.
select distinct
FName
,LName
,convert(varchar(10),AppointmentDate,101)AppointmentDate
from Appointment

How to modify that select to get all appointments for the last 2 month.
Thanks.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-07 : 16:29:11
That select is to modify in the not shown rest of the statement.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-07 : 16:41:50
add
WHERE AppointmentDate >= dateadd(m,-2,getdate())
to your query.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

eugz
Posting Yak Master

210 Posts

Posted - 2009-10-07 : 17:46:59
How to create function that get me result date like 2 month early from appointment date?
Thanks.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-08 : 02:35:54
quote:
Originally posted by eugz

How to create function that get me result date like 2 month early from appointment date?
Thanks.


Why do you want to create a function for this?
Just use it in WHERE clause

Madhivanan

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

eugz
Posting Yak Master

210 Posts

Posted - 2009-10-08 : 09:32:09
I would like to create SP like
procedure [dbo].[sp_Appointments]
(
@AppointmentDate as datetime
)
as

select
Appointment_id
,FName
,LName
,convert(varchar(10),AppointmentDate,101)AppointmentDate
,AppointmentDateFrom
from Appointment

where AppointmentDateFrom I would like to get on 2 month early date then AppointmentDate.
Thanks.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-08 : 10:08:36
procedure [dbo].[sp_Appointments]
(
@AppointmentDate as datetime
)
as

select
Appointment_id
,FName
,LName
,convert(varchar(10),AppointmentDate,101)AppointmentDate
,AppointmentDateFrom
from Appointment
WHERE AppointmentDate >= dateadd(m,-2,@AppointmentDate )


Madhivanan

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

eugz
Posting Yak Master

210 Posts

Posted - 2009-10-08 : 10:24:57
Thanks a lot for help. It works exactly like I expected. Thank you very much.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-08 : 10:31:33
quote:
Originally posted by eugz

Thanks a lot for help. It works exactly like I expected. Thank you very much.


You are welcome

Madhivanan

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

- Advertisement -