Help in Where Clause

  • 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.

  • 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;-)

  • 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[/url]

    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

  • Thanks 500, Ill keep that page handy. 🙂

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply