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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Not filtering criteria

Author  Topic 

lbunch
Starting Member

9 Posts

Posted - 2007-03-22 : 10:25:15
I am trying to filter data from columns and this is just not working. If I select all the criteria below and try to run it - I do not get any records returned.

WHERE (DropDt >= DATEADD(month, DATEDIFF(month, 0, GETDATE()) - 13, 0)) AND (DropDt <= DATEADD(month, DATEDIFF(month, 0, GETDATE()) - 1, 0))
and Type IN ('Employee', 'Refinance')

and Chan IN ('XM', 'BN', 'RS', 'MM')

and Seg IN ('Hoc','LeftOver', 'COnly')

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-22 : 10:28:39
try comment off all but one of the condition and un-comment it one by one to test


KH

Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-03-22 : 11:22:48
It is also helpful to use variables to keep things more readable, and so that you can print out the variable values to ensure that they are getting calculated the way you expect/want:

declare @minDate datetime;
declare @maxDate datetime;

set @minDate= DATEADD(month, DATEDIFF(month, 0, GETDATE()) - 13, 0)
set @maxDate = DATEADD(month, DATEDIFF(month, 0, GETDATE()) - 1, 0)

-- for debugging purposes:
print @minDate
print @maxDate

...

WHERE DropDt >= @minDate AND DropDt <= @maxDate
and Type IN ('Employee', 'Refinance')
and Chan IN ('XM', 'BN', 'RS', 'MM')
and Seg IN ('Hoc','LeftOver', 'COnly')

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

lbunch
Starting Member

9 Posts

Posted - 2007-03-22 : 15:09:01

thanks but still not working. I have tried commenting out and testing -
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-22 : 19:37:53
quote:
Originally posted by lbunch


thanks but still not working. I have tried commenting out and testing -



The where clauses is correct in terms of syntax.
BUT . . .
How do you expect us to help you with only part of the code
and without any business logic,
without any sample data
and without any required result ?


KH

Go to Top of Page
   

- Advertisement -