• RVO (3/14/2013)


    I tried this

    select * from IndustryMap

    WHERE 1 =1

    AND id_cusip = COALESCE(@cusip,id_cusip)

    AND ticker = COALESCE(@ticker,ticker)

    AND exch_code = COALESCE(@exchangeCode,exch_code)

    and was ready to scream Hurray but realized that

    when any of the columns have a null value

    this won't work. Because "AND col = NULL" is not valid.

    Keep searching.... 🙂

    That will get you HORRIBLE plans too for several reasons.

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service