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 |
|
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 databetween from date and to date.it is not working please helpCreate PROCEDURE ReportsByComplaintID (@ToDate DateTime,@FromDate DateTime) ASselect LogID,LogDate,DueDate,Customers.CustomerFirstName+ ' ' + Customers.CustomerLastNameas Name,DetailDescription,ComplaintCategories.CategoryName from ComplaintLog left outer join Customerson ComplaintLog.CustomerID=Customers.CustomerID left outer join ComplaintCategories on ComplaintLog.CategoryID=ComplaintCategories.CategoryIDwhere ComplaintLog.IsActive=1and(@FromDate IS NULL OR (ComplaintLog.DueDate >= @fromDate and ComplaintLog.DueDate <= @ToDate ) ) |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-03-20 : 06:46:54
|
| TryComplaintLog.DueDate >=DateAdd(day,DateDiff(day,0,@fromDate),0) and ComplaintLog.DueDate < DateAdd(day,DateDiff(day,0,@Todate),1)MadhivananFailing to plan is Planning to fail |
 |
|
|
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" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-03-24 : 04:33:52
|
Not recommended though MadhivananFailing to plan is Planning to fail |
 |
|
|
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. KHChoice 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 |
 |
|
|
|
|
|
|
|