| Author |
Help on a SQL statement
|
|
| Bruce W.1 2002-08-03, 3:23 pm |
| I'm no SQL expert but I need a SQL statement for an ASP app.. Am using OleDb to get one row from an Access database table named
Users with an OleDbDataReader. user_ID is the primary key for this table that contains usernames, passwords, company, etc..
string strSQL = "SELECT * FROM Users WHERE user_ID = " + itemValue ;
where itemValue is a string containing the user_ID
Does this statment look right? It doesn't seem to work right.
Thanks for your help.
| |
|
| bruce,
what is the datatype for user_id? is it char or numeric?
your current statement would work fine if user_id is numeric. if it's char,
you would want to change it to this for access:
string strSQL = "SELECT * FROM Users WHERE user_ID = """ & itemValue & """
;"
also, use "&" for concatenation.
--
-oj
Rac v2.1 Public Beta is RELEASED.
http://www.rac4sql.net
"Bruce W.1" <bw1@NOSPAMcorecomm.net> wrote in message
news:3D4C3A3D.3E08C8D7@NOSPAMcorecomm.net...
> I'm no SQL expert but I need a SQL statement for an ASP app.. Am using
OleDb to get one row from an Access database table named
> Users with an OleDbDataReader. user_ID is the primary key for this table
that contains usernames, passwords, company, etc..
>
> string strSQL = "SELECT * FROM Users WHERE user_ID = " + itemValue ;
>
> where itemValue is a string containing the user_ID
>
> Does this statment look right? It doesn't seem to work right.
>
> Thanks for your help.
| |
| Bruce W.1 2002-08-03, 4:23 pm |
| oj wrote:
>
> bruce,
>
> what is the datatype for user_id? is it char or numeric?
>
> your current statement would work fine if user_id is numeric. if it's char,
> you would want to change it to this for access:
>
> string strSQL = "SELECT * FROM Users WHERE user_ID = """ & itemValue & """
> ;"
>
> also, use "&" for concatenation.
>
> --
> -oj
> Rac v2.1 Public Beta is RELEASED.
> http://www.rac4sql.net
>
==============================
==============================
===========
The data type is an (Access autonumber) long int. This ampersand for contatenation confuses me. Is this imbedded in the string?
I was using it to construct the string. How is '&' used?
| |
| David Wier 2002-08-03, 4:23 pm |
| strSQL = "SELECT * FROM Users WHERE user_ID = " & itemValue
First of all - like oj asked, some of this depends on the datatype of
the user_id field....if it's numeric, you do the statement like above.
If it's not, you do :
strSQL = "SELECT * FROM Users WHERE user_ID = '" & itemValue & "'"
I have a tutorial on my site concerning the use of single & double
quotes along with variables in SQL statements:
http://aspexpress.com/tutorials/tutorial.asp?id=2
David Wier
Http://aspexpress.com
The best ASP Text Editor in the Galaxy
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
| |
|
| bruce,
"&" is normally used to construct the string.
this should work then:
strSQL = "SELECT * FROM Users WHERE user_ID = " & itemValue
response.write strSQL
--
-oj
Rac v2.1 Public Beta is RELEASED.
http://www.rac4sql.net
"Bruce W.1" <bw1@NOSPAMcorecomm.net> wrote in message
news:3D4C4D71.1C6A7B39@NOSPAMcorecomm.net...
>
> The data type is an (Access autonumber) long int. This ampersand for
contatenation confuses me. Is this imbedded in the string?
> I was using it to construct the string. How is '&' used?
| |
| David Wier 2002-08-03, 4:23 pm |
| It's best to use the Ampersand is use to concatenate strings - and the +
sign for additions of numeric entities
David Wier
Http://aspexpress.com
The best ASP Text Editor in the Galaxy
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
|
|
|
|