sql - WHERE clause returning incorrect records -


i'm using this

declare @year_filter_start datetime set @year_filter_start = dateadd( dd, -1, dateadd( yy, datediff( yy, 0, getdate() ), 0 ) ) declare @year_filter_end datetime set @year_filter_end = getdate()  insert table   ( blah ) select blah   other_table  actissuedate null      or actstartdate between @year_filter_start , @year_filter_end 

and it's returning records actissuedate not null , actstartdate not between year start , today. @year_filter_start supposed beginning of year, @year_filter_end supposed today.

for example:

a record actstartdate 2010-08-02 , actissuedate 2011-03-15

or actstartdate 2009-05-18 , actissuedate 2009-09-06

is there wrong statement?

try following, need few more parentheses think:

where ((actissuedate null)       or (actstartdate between @year_filter_start , @year_filter_end)) 

the engine sees 2 statements way have it. need make one.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -