|
|
 |
| SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Language section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

June 24th, 2005, 11:26 AM
|
|
Authorized User
|
|
Join Date: Jan 2005
Location: , , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
SQL "equals operator" in queries
Please can you tell me what is wrong with this function?
When I pass strings for valueA and valueB, it works OK. But when I pass integers for valueA and valueB it does not work.
Does the "=" operator work for strings only? If so, how can I generalise this function to work no matter what type of variable valueA and valueB are?
------------
Function GetData(cursor, locking, table, fieldA, valueA, fieldB, valueB, order)
Dim rsData
Dim strSQL
strSQL = "SELECT * FROM " & table & _
" WHERE " & fieldA & " = " & valueA & " AND " & fieldB & " = " & valueB & _
" ORDER BY " & order & " ASC;"
Set rsData = Server.CreateObject("ADODB.RecordSet")
rsData.Open strSQL, dcnDB, cursor, locking
Set GetData = rsData
End Function
------------
|

June 24th, 2005, 11:42 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by Steve777
When I pass strings for valueA and valueB, it works OK. But when I pass integers for valueA and valueB it does not work.
|
Are you sure about that? I would guess that your code fails just the other way around; i.e. it works for integers and numbers in general and fails for strings.
Consider what the generated SELECT statement would look like when I use the string abc for valueA and xyz for valueB, and use the 'field' (they're not fields in a relational database, they're columns) names fieldA and fieldB:
Code:
SELECT * FROM table WHERE fieldA = abc AND fieldB = xyz
ORDER BY order ASC;
The string values abc and xyz have to be quoted for the SELECT syntax to be legal.
It sometimes is helpful to put a debugging statement in there to display the generated SQL text string when things aren't working right.
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |