Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 24th, 2005, 10:26 AM
Authorized User
 
Join Date: Jan 2005
Posts: 46
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

------------
 
Old June 24th, 2005, 10:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.