Results 1 to 3 of 3

Thread: SQL wont work

  1. #1
    Join Date
    Dec 2005
    Posts
    8

    Unanswered: SQL wont work

    Can anyone suggest why this SQL wont work?

    Someone has suggested that I have a few " in the wrong place.
    I am missing the basic understanding about variable / string concatenation.

    SELECT SupplierName, Location, ShortDescription FROM Query1 WHERE 'TimberSpecies' LIKE '%" & " + Replace(rsSearchResult__MMColParam, "'", "''") + " & "%' AND 'CategoryTable' LIKE '%" & " + Replace(rsSearchResult__MMColParam2, "'", "''") + " & "%' AND 'Location' LIKE '%" & " + Replace(rsSearchResult__MMColParam3, "'", "''") + " & "%' ORDER BY SupplierName"

    Thanks

    Mally.

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    --In the query analyzer execute this after specifying datatypes

    CREATE PROC MyProc
    @param1 <insertdatatype>,@param2 <insertdatatype>,@param3 <insertdatatype>
    AS
    SELECT SupplierName, Location, ShortDescription
    FROM Query1
    WHERE TimberSpecies LIKE '%' + @param1 + '%'
    AND CategoryTable LIKE '%' + @param2 + '%'
    AND Location LIKE '%' + @param3 + '%'
    ORDER BY SupplierName

    --FROM YOUR application CODE execute

    SET rs = con.EXEC ("MyProc @param1 = " & Replace(rsSearchResult__MMColParam, "'", "''") & ",@param2 = " & Replace(rsSearchResult__MMColParam2, "'", "''") & ",@param3 = " & Replace(rsSearchResult__MMColParam3, "'", "''") & ")
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •