p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Database > SQL Language
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 24th, 2005, 11:26 AM
Authorized User
Points: 206, Level: 4
Points: 206, Level: 4 Points: 206, Level: 4 Points: 206, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: , , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

------------
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old June 24th, 2005, 11:42 AM
Friend of Wrox
Points: 2,591, Level: 21
Points: 2,591, Level: 21 Points: 2,591, Level: 21 Points: 2,591, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Combine sql queries snufse SQL Server 2005 16 June 17th, 2008 04:47 PM
Invalid operator for data type. Operator equals di Pusstiu SQL Server 2000 2 August 10th, 2007 05:51 AM
SQL 'Between' operator daveyh BOOK: Beginning SQL 2 April 4th, 2007 04:25 PM
Anyone Expert in SQL Queries? itHighway HTML Code Clinic 3 June 3rd, 2005 10:57 AM
Anyone Expert in SQL Queries itHighway Classic ASP Basics 2 May 24th, 2005 04:37 AM



All times are GMT -4. The time now is 01:57 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc