Syntax for a DB Query

Results 1 to 3 of 3

Thread: Syntax for a DB Query

  1. #1
    Join Date
    Dec 1969

    Default Syntax for a DB Query

    I&#039;m having trouble using multiple string queries in my SQL statement. I&#039;m trying to use a string query for both the FROM and WHERE clauses. It works without the WHERE clause... this line here:<BR><BR>recordSet.Open "SELECT * FROM " &Request.QueryString("Doc"), connectionToDatabase<BR><BR>but when I add the WHERE clause to make it this:<BR><BR>recordSet.Open "SELECT * FROM " &Request.QueryString("Doc") &" WHERE Job= " &Request.QueryString("JobName"), connectionToDatabase<BR><BR>I get an error - Too few parameters. Expected 1.<BR><BR>From fooling around with the placement of spaces I get another error - Syntax error in FROM clause. <BR><BR>I have no idea what the right syntax is... Help?<BR>Thanks,<BR><BR>Dan<BR>DreamThrall@worldne

  2. #2
    Join Date
    Dec 1969

    Default RE: Syntax for a DB Query

    put <BR><BR>&#039; around your string var name &#039;

  3. #3
    Eddie Campbell Guest

    Default RE: Syntax for a DB Query

    I would guess that JobName is a string, if so you need to add &#039; marks around it like this:<BR><BR>recordSet.Open "SELECT * FROM " &Request.QueryString("Doc") &" WHERE Job= &#039;" &Request.QueryString("JobName") & "&#039;", connectionToDatabase<BR><BR>A neater way of doing this is to build the Sql into a string which you can response.write to screen when you get problems<BR>e.g.<BR>MySql = "SELECT * FROM " &Request.QueryString("Doc") &" WHERE Job= &#039;" &Request.QueryString("JobName") & "&#039;"<BR><BR>Response.Write MySql<BR>recordSet.Open MySql, connectionToDatabase<BR><BR>Obviusly, get rid of the Response.write once it works.

Posting Permissions

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