Use variable in SQL

Use variable in SQL

Post by le.. » Sun, 06 Jun 1999 04:00:00



Hi,
Suppose I have a SQL statement like
 "Select * from customer where ID = '1756' "
if I want to replace '1756' as a variable like idno = "1756",
how the SQL statement look like ?
 "Select * from customer where ID = idno " can not work. Please help ?

Thanks in advance.
G.H.

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

 
 
 

Use variable in SQL

Post by Ted Gordo » Sun, 06 Jun 1999 04:00:00


"Select * from customer where ID = '" & idno & "'"
Where there are an odd number of quote marks, it is an enclosed single quote
within a double quote enclosed string.
Good luck,
Ted Gordon

>Hi,
>Suppose I have a SQL statement like
> "Select * from customer where ID = '1756' "
>if I want to replace '1756' as a variable like idno = "1756",
>how the SQL statement look like ?
> "Select * from customer where ID = idno " can not work. Please help ?

>Thanks in advance.
>G.H.

>Sent via Deja.com http://www.deja.com/
>Share what you know. Learn what you don't.


 
 
 

Use variable in SQL

Post by FMein703 » Mon, 07 Jun 1999 04:00:00


Dear G.H.,
here is a solution:

If the type of ID is long, write:

IDno = 1756
SQL = "SELECT * FROM customer" _
& " WHERE ID = " & IDno & ";"

if you want to select all ID's beginning with 17, then write:

IDno = 17
SQL = "SELECT * FROM customer" _
& " WHERE ID Like " & IDno & "*;"

Have fun!

                                          Franko

 
 
 

Use variable in SQL

Post by A.Schmid » Wed, 16 Jun 1999 04:00:00


If you use the SQWl-Statement in VBA, then there are two posibilities:
1.: idno is STRING
idno="1234"
"Select * from customer where ID = ' " & idno " ';"

2.: idno is number
idno=1234
"Select * from customer where ID = " & idno & ";"


Quote:> Hi,
> Suppose I have a SQL statement like
>  "Select * from customer where ID = '1756' "
> if I want to replace '1756' as a variable like idno = "1756",
> how the SQL statement look like ?
>  "Select * from customer where ID = idno " can not work. Please help ?

> Thanks in advance.
> G.H.

> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.

 
 
 

1. problem with using variables in SQL statement

hi..  being relatively new to SQL  (2 days :)  I'm about to ask a
probably stupid question, but please bear with me...

I have an Access database, and have created a form with which you can
enter a search string and search the database.  I'm doing this using a
normal form and post command, and grabbing the inputted form string,
which I assign to a varible...   Everything works fine as long as I
include an entire word to search for...  but when I use the LIKE
command, things don't go quite as I would expect..  (and not like the
books or reference materials tell me it should..)

example:

first I grab the string from the form....

searchterm=Request.Form("search")

then I insert it into a SQL statement:

Set RS = MyConn.Execute("SELECT word, definition FROM glossary where
word LIKE '"& searchterm &"' ;")

my problem is that this works exactly as if I had used the = operator
instead of LIKE, returning a match only if the exact word I enter is
in the table.

If I hardcode a search term string using LIKE, then it performs as
expected.. and  returns any entry that resembles my search term, but
when I use a variable, it doesn't...

can someone Please tell me what I'm doing wrong?

thanks...  -paul

2. Star vs snowflake schema

3. Newbie Q: Using variables in SQL

4. DTS - Connection Datasource prob.

5. using variable from SQL

6. Max Function in SQL Statement

7. using variables in sql

8. Paradox 4.0/Best PAL limitaion. Any work arounds?

9. Newbie Q: Using variables in SQL

10. Using variable in SQL statement

11. Selection using variables in SQL ?

12. Help! Using variables in SQL statement