Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Help in Where Clause Expand / Collapse
Author
Message
Posted Wednesday, September 18, 2013 7:13 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, October 8, 2013 8:23 AM
Points: 11, Visits: 17
Hi All,
Im stuck and need some help, I have 3 out of 4 variables working in my Where clause and need help getting the 4th one to work. My variables are @startdate, @enddate, @class, @STdrp.

The date range works fine and when I filter for @class that works as well, but the @STdrp when I choose something there it returns those results, but everything else as well. How can I just get back what was passed as @STdrp?

Im sure the way I wrote this is pretty messy, my apologies Im not as good on the back end as I am the front end. :)
    
WHERE
(
ct.AlertedDate between @startdate and @enddate
OR
ct.[Dispo] = @STdrp
OR
ct.[AcceptStatus] = @STdrp
--OR
-- @STdrp = '%'
)
AND
isnull(QC.Class,'BB') like @class
AND
@startdate <= ct.AlertedDate
ORDER BY ct.[AlertedDate]

Thanks for your advice.
Post #1495916
Posted Wednesday, September 18, 2013 7:37 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 12:26 AM
Points: 2,840, Visits: 3,963
51 views ( last including mine) but NO response and the reason is :
No sample data
NO business rule or logic
NO table definition on this post.

Include them and i am sure people will see this with interest.

and on your post ..one blind shot.... it could be happening becaise you have OR operator with concern fourth variable.


-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #1495923
Posted Wednesday, September 18, 2013 7:39 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Thursday, June 26, 2014 4:08 AM
Points: 708, Visits: 3,286
Firstly, I would recommend a quick read of the below as a refresher:

http://technet.microsoft.com/en-us/library/ms186992(v=sql.105).aspx

I would change your code to the below:

WHERE 
( ct.AlertedDate between @startdate and @enddate OR ct.[Dispo] = @STdrp )
AND
isnull(QC.Class,'BB') = @class
AND
ct.[AcceptStatus] = @STdrp

ORDER BY ct.[AlertedDate]



---------------------------------------------------------


It takes a minimal capacity for rational thought to see that the corporate 'free press' is a structurally irrational and biased, and extremely violent, system of elite propaganda.
David Edwards - Media lens

Society has varying and conflicting interests; what is called objectivity is the disguise of one of these interests - that of neutrality. But neutrality is a fiction in an unneutral world. There are victims, there are executioners, and there are bystanders... and the 'objectivity' of the bystander calls for inaction while other heads fall.
Howard Zinn
Post #1495925
Posted Wednesday, September 18, 2013 7:52 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, October 8, 2013 8:23 AM
Points: 11, Visits: 17
Thanks 500, Ill keep that page handy. :)
Post #1495930
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse