Using variables in an SQL statement

Results 1 to 3 of 3

Thread: Using variables in an SQL statement

  1. #1
    Rob Guest

    Default Using variables in an SQL statement

    Can someone tell me the correct way of specifying asp variables in an SQL statement so that the database does not use the variable name to try and match with the table but the value contained in the variable.<BR>I have a statement such as <BR>set objRs=objConn.Execute("SELECT * from my_table where name like &#039%variable1%&#039") now I know this does not work because this statement literally compares variable1 to the database. I want the contents of variable1 checked.<BR>Thanks for any help you can provide.

  2. #2
    Svein Vargan Guest

    Default RE: Using variables in an SQL statement

    First, it&#039s a good idea to remove the SELECT query from the parenthesis, it&#039s better to refer to it like this:<BR><BR>Dim SQLQRY<BR>SQLQRY="SELECT................"<BR>set objRs=objConn.Execute(SQLQRY)<BR><BR>If variable is not numeric in db, use:<BR>...WHERE ((NAME like &#039%" & variable1 & "%&#039) AND/OR (somefield like &#039%" & somevariable & "%&#039).....<BR><BR>If variable is numeric:<BR>...WHERE NUMBER=" & variable1<BR>If more conditions are necessary, add new line beneath:<BR>SQLQRY=SQLQRY & "AND somefield=" & somevariablefield<BR>This can be repeated over and over....<BR><BR>Best reegards<BR><BR>Svein Vargan<BR><BR>

  3. #3
    Rob Guest

    Default Thanks for the help Svein.

    I have solved my problem with your help

Posting Permissions

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