Passing a parameter to a query.

Results 1 to 3 of 3

Thread: Passing a parameter to a query.

  1. #1
    MarkySparkis Guest

    Default Passing a parameter to a query.

    Is there any simple way to pass a parameter in ASP code to an already-created Access parameterized query. For example, the SQL in the Access query (let&#039;s call it qryApples) may look like this: <BR><BR>PARAMETERS [Enter Year] Short; <BR>SELECT tbl_Test.Year_Of_Picking, tbl_Test.Number_apples <BR>FROM tbl_Test <BR>WHERE (((tbl_Test.Year_Of_Picking)=[Enter Year])); <BR><BR>I do not want to do dynamic SQL as this involves a query in a query. I just want to some way have ASP stuff the year into the parameter. Any help would be appreciated. <BR><BR>Mark

  2. #2
    J. Paul Schmidt Guest

    Default No

    But perhaps consider using some dynamic SQL like the following:<BR><BR>strSQL = "SELECT tbl_Test.Year_Of_Picking, tbl_Test.Number_apples FROM tbl_Test WHERE tbl_Test.Year_Of_Picking = " & MyYearVariable<BR><BR>Nothing extra is needed around the criterion for a numeric field like the above, a single quote would be needed before and after a text field criterion, and a # would be needed before and after a date field criterion.<BR><BR>Best regards,<BR>-Paul<BR><BR>J. Paul Schmidt, MBA<BR>Databases on the Web<BR><BR>

  3. #3
    Byron Stout Guest

    Default RE: No er... Yes

    Yes, I have done this before. Using an ADO connection to your Access DB, setup your connection then do something like this<BR><BR>sSQL = "qryApples " & intYear<BR>Set objRep = Server.CreateObject("ADODB.Recordset")<BR>objRep.O pen sSQL, objConn, adOpenForwardOnly, , adCmdStoredProc<BR><BR>The important thing to do is add the adCmdStoredProc to the options so ADO knows how to handle that parameter...<BR><BR>cheers,<BR>Byron.<BR>

Posting Permissions

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