crystaldev1
Programmer
Hello. I am using CR 9 and SQL Server 2005. I would like to get some feedsbacks regarding a better approach rather than using 10 if-then-else statements. I have 10 fields which I would need to sort through in the record selection for each record. I have a date range parameters @StartDate and @EndDate which the report is based off.
For example, I have a table called "Software". In that table, I have 10 different fields (Date1, Date2, Date3, ...,Date10) in date ascending respectively. What I would like to do is first, select the latest Date field that is not null (so check Date10, then Date9, then Date8 ...). Once the Date field is selected and if the selected Date field falls within the date range parameter, then I need to select that record.
So I have if statement as follows:
(if not isnull(Date10) then Date10
else if not isnull(Date9) then Date9
else if not isnull(Date8) then Date8
.............
else if not isnull(Date1) then Date1) in
[@StartDate,@EndDate].
I would like to know if there's a better approach to this. Thanks.
For example, I have a table called "Software". In that table, I have 10 different fields (Date1, Date2, Date3, ...,Date10) in date ascending respectively. What I would like to do is first, select the latest Date field that is not null (so check Date10, then Date9, then Date8 ...). Once the Date field is selected and if the selected Date field falls within the date range parameter, then I need to select that record.
So I have if statement as follows:
(if not isnull(Date10) then Date10
else if not isnull(Date9) then Date9
else if not isnull(Date8) then Date8
.............
else if not isnull(Date1) then Date1) in
[@StartDate,@EndDate].
I would like to know if there's a better approach to this. Thanks.