• shilpaprele (10/8/2012)


    I have one procedure with parameter @P.

    If @p= null & table abc has many rows with col1 = null, then following select does not reurn the values

    select *

    from abc

    where col1 = @P

    what should be correct the syntax( do not wan tto use set ansi null on/off).

    The correct way, to return records, would be:

    select *

    from abc

    where col1 = @P OR (@P IS NULL AND col1 IS NULL)

    Using, ISNULL function on a column would stop this query to SARGable if you have an index on Col1

    Saying all the above, you should really read Gail Shaw's paper on catch-all-queries :

    http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]