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 |
|
RaghaSM
Yak Posting Veteran
52 Posts |
Posted - 2009-03-10 : 13:16:56
|
| Hi All,I have four differnt dates in my table - AddedDate, UpdatedDate, DeletedDate, SubmiitedDate .When the user selects the date range and the datetype ( above mentioned four types)they should be able to view the relevant data.I am writing a stored proc that has input parameters - type ,startdate and enddate. Also this stored procedure data has to retrived by creating so many temporary tables inside the stored proc and uses so many joins ( this would be around 40 lines ) ....but only condition that should vary shopuld be for the type of date they selected. i.e., when provided the type - "Addeddate" and start abnd enddates. the only where condition changes something like this- " where addeddate between @startdate and @enddate"similarly applies for the other date types.. currently the only process I know to implement is :writing the if conditions and writing the same set of code for all the date types with a different where condition.I am sure that there would be a better approach instead of this redundancy.. can somebody please help me by guiding how to proceed?Your help would be very much appreciated.Thanks. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-10 : 13:21:51
|
no if conditions needed. just use the following where condition:-...WHERE (addeddate between @startdate and @enddate OR type<> 'AddedDate')AND (UpdatedDate between @startdate and @enddate OR type<> 'UpdatedDate')AND (DeletedDate between @startdate and @enddate OR type<> 'DeletedDate')AND (SubmiitedDate between @startdate and @enddate OR type<> 'SubmiitedDate') |
 |
|
|
RaghaSM
Yak Posting Veteran
52 Posts |
Posted - 2009-03-10 : 13:39:05
|
| Thanks alot Visakh.. This makes it much easier. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-10 : 13:42:21
|
| welcome |
 |
|
|
|
|
|