Home Forums SQL Server 2008 T-SQL (SS2K8) Filter Countries, States and Cities which in same row in one table. RE: Filter Countries, States and Cities which in same row in one table.

  • Bhuvnesh (10/8/2013)


    ChrisM@Work (10/8/2013)


    SELECT * FROM TABLE WHERE countryid = @country

    SELECT * FROM TABLE WHERE countryid = @country AND stateID = @stateid

    SELECT * FROM TABLE WHERE countryid = @country AND stateID = @stateid AND Cityid = @Cityid

    totally agree with you Chris.. but i think here OR operator will be more reliable because with correct data

    OR and AND will return same records ..What do you think ?

    Gosh, I wouldn't rely on that nuance especially for the sake of clarity. I would absolutely use AND in this case just to avoid any confusion in the heat of an emergency fix, should it ever occur. A newbie wouldn't understand the ORs are an implied AND simply because of the IDs involved.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)