Please Help me with this query

Results 1 to 3 of 3

Thread: Please Help me with this query

  1. #1
    Join Date
    Dec 1969

    Default Please Help me with this query

    I want to pass a parameter to a stored query in Access like this:<BR>SELECT Name, Last FROM [@theTable];<BR><BR>Then in the .asp page...<BR>conn.Execute (Exec ThisQuery &#039;ThisTable&#039;)<BR><BR>But I just get an error saying that the database cannot find the &#039;@theTable&#039; Table. It seems to me that this clause is not right to pass a parameter like that. Could you please shed me some light on how to do it? <BR><BR>Thank you for your help.<BR><BR>Edwin

  2. #2
    Join Date
    Dec 1969

    Default Maybe I'm missing something...

    ...unless the query is much more complex than the one you posted, surely this could be accomplished through a normal query rather than one of Access&#039; stored queries?<BR><BR>&#060;%<BR><BR>Dim objConn, objRS<BR><BR>&#039; Create connection and recordset objects<BR>Set objConn = Server.CreateObject("ADODB.Connection")<BR>Set objRS = Server.CreateObject("ADODB.RecordSet")<BR>objConn. Open(strConnectionString)<BR><BR>&#039; Execute the query<BR>Set objRS = objConn.Execute("SELECT Name, Last FROM [" & strTableName & "]")<BR><BR>&#039; See if any data was returned<BR>Dim arrRecordSetData, bFoundRecords<BR>bFoundRecords = False<BR>if objRS.EOF = False then<BR> bFoundRecords = True<BR> &#039; Store returned data in an array (much faster than an RS object)<BR> arrRecordSetData = objRS.GetRows()<BR>end if<BR><BR>&#039; Close & destroy objects<BR>objRS.Close<BR>objConn.Close<BR>Set objRS = Nothing<BR>Set objConn = Nothing<BR><BR>%&#062;<BR><BR>I&#039;m willing to hear any arguments against it, but it seems viable to do it that way. Don&#039;t try and confuse Access queries with SQL Stored Procedures - there is no speed increase in using them, especially if the query is as simple as that.<BR><BR>Craig.

  3. #3
    Join Date
    Dec 1969

    Default RE: Please Help me with this query

    don&#039;t know if this works in access but in SQL server you would do<BR><BR>EXEC (&#039;SELECT Name, Last FROM &#039; + @theTable )<BR><BR>You have to concate the string and execute it.<BR><BR>in your asp page:<BR><BR>conn.Execute("EXEC ThisQuery &#039;ThisTable&#039;")<BR><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