where clause

  • Hi

    I have below parameters .

    @frDate date,

    @toDate date,

    @VName nvarchar(100) = null,

    @CName nvarchar(100) = null,

    I want if user has entered nothing in VName and Cname then

    where should be between @frDate and @ Todate

    If user has entered Vname & Dates then

    all records with date range and Vname = @ Vname and all CName records like so on

    Thanks

     

     

  • IF <test>

    BEGIN

    SELECT... FROM...WHERE... <params>

    END

    ELSE

    SELECT...FROM WHERE <different params>

    There's nothing stopping you from forking the two queries with an IF statement.

  • It's beginning to look a lot like ... a catch-all query.

    I suggest you get yourself a nice drink and read this article: https://sqlinthewild.co.za/index.php/2018/03/13/revisiting-catch-all-queries/

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

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

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