The following works only when I change the "AND" to "OR".
declare @ows_table varchar(50)
declare @more varchar(10)
declare @less varchar(10)
set @ows_table = 'ows_project2_u_trainingauthorization'
set @more = '12/20/2002'
set @less = '12/15/2002'
--this should find any results between 12/15 and 12/20
EXEC(
'SELECT tp_Body, tp_Author, tp_Title, tp_Created
FROM ' + @ows_table +
' WHERE DateDiff(day,' + @more + ',tp_Created) < 0 AND
DateDiff(day,' + @less + ',tp_Created) > 0'
)
It's actually part of a stored procedure that I converted for testing QA, that's why it looks odd. The second part of the predicate always works (@less) but the first part (@more) refuses. Any clues?
declare @ows_table varchar(50)
declare @more varchar(10)
declare @less varchar(10)
set @ows_table = 'ows_project2_u_trainingauthorization'
set @more = '12/20/2002'
set @less = '12/15/2002'
--this should find any results between 12/15 and 12/20
EXEC(
'SELECT tp_Body, tp_Author, tp_Title, tp_Created
FROM ' + @ows_table +
' WHERE DateDiff(day,' + @more + ',tp_Created) < 0 AND
DateDiff(day,' + @less + ',tp_Created) > 0'
)
It's actually part of a stored procedure that I converted for testing QA, that's why it looks odd. The second part of the predicate always works (@less) but the first part (@more) refuses. Any clues?