Windows Vista Forums

SQL question with Autocomplete functionality

  1. #1


    mazdotnet Guest

    SQL question with Autocomplete functionality

    Hi,

    I'm working on a little autocomplete functionality with the AJAX
    toolkit. I like to the following,

    Take the following 2 SQLs
    SELECT NAME FROM COUNTRIES WHERE NAME LIKE '%TORONTO%' (would return
    false)
    SELECT NAME FROM CITIES WHERE NAME LIKE '%TORONTO%' (would return
    true)

    I like to have a stored procedure that does this. How do you write the
    IF condition. Bascially I want it to first check the countries table
    and if not matches there , next go to the CITIES table and check it
    there? or is there a way to check both tables at once and return only
    a single resultset combining both matches in COUNTRIES and CITIES
    table? (in a single column 'Name'?)



    Thank you
    M.

      My System SpecsSystem Spec

  2. #2


    Marc Gravell Guest

    Re: SQL question with Autocomplete functionality

    If you want all the matches (i.e. no short-circuiting - check all the
    tables) then UNION / UNION ALL are your friend; just lob UNION between your
    two SELECTs and you're done - but make sure you keep the column types
    compatible in each select (SQL Server 2005 gets very upset otherwise)

    If you want to short-circuit (i.e. if any contries are found, don't check
    cities) then you would be best to create a holding-pen (perhaps DECLARE
    @names TABLE ([Name] varchar(100) NOT NULL)) and then do an INSERT @names
    ([Name]) SELECT... and check the @@ROWCOUNT (or check for rows in @names).
    If no rows were inserted, then run the next INSERT/SELECT etc. Finally,
    SELECT [Name] FROM @names ORDER BY [Name]

    Marc



      My System SpecsSystem Spec

SQL question with Autocomplete functionality

Similar Threads
Thread Thread Starter Forum Replies Last Post
WLM will not autocomplete Johninbideford Live Mail 2 25 Aug 2009
Solved autocomplete RDA1959 Microsoft Office 3 11 Apr 2009
AutoComplete Ron Vista account administration 1 28 Oct 2007
Media Center Functionality Question Barry Watzman Vista General 0 13 Oct 2006
Autocomplete Sam Jost Avalon 0 14 Jun 2006