How to reference user input in a query

  • OK I'm quite new to SQL Server so please be gentle

    This is the problem I am faced with

    I have an SQL db and an Access adp that interfaces with it in the adp file I have a form that a user can enter a town name in I then want to use a query to filtre matching records for the same town. I am able to do this when it is just in Acess but SQL Server doesn't like the code I dont know where to start, any help very greatfully received.

  • Select * from Table_Name where TownName=:TownName

    Where :TownName is a paramter to which you must assign a value in your Access app. I would suggest that you avoid filters such as you'd use in an Access db, as a query is a lot more efficient and limits the result set to just what you are looking for.

    Hope this helps

    Regards,

    Morpheus


    "See how deep the rabbit hole goes..."

  • Cheers Morpheus

    But I didn't explain myself well enough, what I need to do is search on a user entered criteria. So for example a user types in a town name and clicks on search then the query will match and display all entries that match what the user has searched on.

    Why oh why does the client not want this on a web page is beyond me! if they did this would have been a 5 minute job ho hum!

    Matt

  • Not quite sure, if I understand you, but see if this helps:

    http://www.sommarskog.se/dyn-search.html

    And in case, that goes your direction, you'd better read this http://www.sommarskog.se/dynamic_sql.html , too. Try to convince your client that such kind of "freetext" thingy is insecure by nature, doesn't perform very good and, and, and.... 

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

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

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