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 query help

Author  Topic 

soniyakapoor03
Starting Member

11 Posts

Posted - 2006-03-20 : 06:41:13
hi,
i am new to sql .
please help.
I want to select a set of data
between from date and to date.
it is not working please help

Create PROCEDURE ReportsByComplaintID
(
@ToDate DateTime,
@FromDate DateTime
)
AS

select LogID,LogDate,DueDate,Customers.CustomerFirstName+ ' ' + Customers.CustomerLastName
as Name,DetailDescription,ComplaintCategories.CategoryName from ComplaintLog left outer join Customers
on ComplaintLog.CustomerID=Customers.CustomerID
left outer join ComplaintCategories on ComplaintLog.CategoryID=ComplaintCategories.CategoryID
where ComplaintLog.IsActive=1
and(@FromDate IS NULL
OR (
ComplaintLog.DueDate
>= @fromDate and ComplaintLog.DueDate <= @ToDate
) )

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-20 : 06:46:54
Try

ComplaintLog.DueDate >=DateAdd(day,DateDiff(day,0,@fromDate),0) and
ComplaintLog.DueDate < DateAdd(day,DateDiff(day,0,@Todate),1)

Madhivanan

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

a_r_satish
Yak Posting Veteran

84 Posts

Posted - 2006-03-24 : 01:25:39
I think another alternative would be to convert the date(part alone) to varchar datatype and then compare..

something like this :

convert(varchar(10),getdate(),120)
This would surely work.

Regards,
satish.r
"Known is a drop, Unknown is an Ocean"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-24 : 04:33:52
Not recommended though

Madhivanan

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

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-24 : 04:44:12
Yup. Bad for performance. Will result in table scan. Use Madhivanan's method instead.



KH

Choice is an illusion, created between those with power, and those without.
Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant

Go to Top of Page
   

- Advertisement -