Using Variables in SQL queries

Results 1 to 2 of 2

Thread: Using Variables in SQL queries

  1. #1
    Sharron Elina Guest

    Default Using Variables in SQL queries

    1.Whenever i use Access database and do some kind of random selection of a record from total records in a table, i find that if the number of records is less than 10 it shows some strange error and does not select record randomly. <BR>-------------------------------------------------------------------------------- <BR>2.How can i use a variable in a SQL query <BR>eg.. Let " Selection " be a variable: <BR>Selection=Int(TotalRecord*rnd)+1 <BR>RS.Open" SELECT * FROM tableZ WHERE ID = " & Selection <BR><BR>"""""""""""""""""""""""""" <BR>is the above code correct? if yes then why does it not work?How can i use the variable "Selection" in the "WHERE" clause. <BR>I am using Access Database

  2. #2
    Kasper Guest

    Default Some tips

    These are merely some tips.<BR><BR>question 1) i suggest you show us the &#039strange error&#039<BR>question 2) <BR>- did you randomize? <BR>- is id in your database a numeric field (if it is a textfield surround it with &#039&#039) ?<BR>- close your sql statements with semicolon ;<BR>- specify the connection for<BR>e.g. : "SELECT * FROM tablez WHERE id="&selection&";",conn<BR>where conn is your connection object ofcourse.<BR><BR>Stating the exact error messages could help a lot in resolving the issue!<BR><BR>Kasper.

Posting Permissions

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