Last post Feb 11, 2015 05:49 PM by JoyceW
Feb 11, 2015 02:25 PM|nissan|LINK
I have a column called "ActiveDate". This date is null before Jan 2015.
But there will be data in this column from Jan 2015.
I need to add a filter to select data(locations) based on the reporting date.
lets say Reporting date is '2/1/2015'
then get all locations whose "ActiveDate" is in february or prior to february.
Remember ACtive date is a nullable date. So how do I frame my where condition.
And another condition is if ActiveDate is null then take into consideration another date column called "CreatedDate". So the condition would be
get all locations whose "CreatedDate" is in february or prior to february.
So Createddate should act as activedate when active date is null.
Feb 11, 2015 02:34 PM|gimimex|LINK
Considering the performance I believe you should try:
(ActiveDate <= @DateParameter) or
(ActiveDate is null and CreatedDate <= @DateParameter)
Hope this helps.
Feb 11, 2015 02:38 PM|JoyceW|LINK
If both dates are null should they be included or excluded from the query?
Feb 11, 2015 02:43 PM|nissan|LINK
CreatedDate will never will be null
Feb 11, 2015 02:46 PM|JoyceW|LINK
where isNull(ActiveDate, CreatedDate) <=
Feb 11, 2015 04:23 PM|nissan|LINK
Oh Thank you. Just one line hah.
Feb 11, 2015 05:49 PM|JoyceW|LINK