String In Query Syntax

Results 1 to 3 of 3

Thread: String In Query Syntax

  1. #1
    shed7 Guest

    Default String In Query Syntax

    What is the correct syntax to use when including a string variable in a WHERE test in a SQL query with Access as the db?<BR><BR>I am receiving &#039Data Type Mismatch&#039 for the following.<BR><BR>Code:<BR><BR>&#060;%@ Language= "VBScript"%&#062;<BR><BR>&#060;%<BR><BR>strNam e = Request.Form.Item("clientname")<BR><BR>Set objConn = Server.CreateObject("ADODB.Connection")<BR>objConn .Open "Test"<BR><BR>Set objRec = Server.CreateObject("ADODB.Recordset")<BR>objRec.A ctiveConnection = objConn <BR><BR>strSQL = "SELECT * FROM Customer WHERE CustomerID = " & "&#039" & strName & "&#039"<BR><BR>objRec.Open strSQL<BR><BR>%&#062;<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: String In Query Syntax

    TRY<BR><BR>strSQL = "SELECT * FROM Customer WHERE CustomerID =&#039" & strName & "&#039"<BR><BR>but, are you sure your CustomerID is a string, because if not then this will cause the error. If your CustomerID is a number (int) then try<BR><BR>strSQL = "SELECT * FROM Customer WHERE CustomerID = " & strName<BR><BR>HTH<BR><BR><BR><BR>

  3. #3
    shed7 Guest

    Default RE: String In Query Syntax

    It works.<BR>It is a string.<BR><BR>Many thanks!

Posting Permissions

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