SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 11th, 2005, 05:43 AM
jjd228 jjd228 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 46 jjd228 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 31 sec
Reputation Power: 5
which to use: LIKE, =, IN... help!!!

im pulling information out of a DB2 database on an AS/400 and get different, sometimes strange results
depending on which i use. im not doing any math on any of the fields i pull in, although most of the fields hold numerical data...
but im only displaying it on a webpage... so for example lets say a customer number is 150 and i want to display records that match
that customer number:

A) SELECT CUSNO WHERE CUSNO = 150
B) SELECT CUSNO WHERE CUSNO = '150'
C) SELECT CUSNO WHERE CUSNO LIKE '150'

and then i can also do something with the "IN" keyword like:

SELECT CUSNO WHERE CUSNO IN (150)
SELECT CUSNO WHERE CUSNO IN ('150')

so which way is the "right" way? i think im being confused by whether or not to use "=" and whether or not to use single quotes...
anyone wanna shed some light on this for me?
thank you!

Reply With Quote
  #2  
Old February 11th, 2005, 10:07 AM
asmoran asmoran is offline
ASPFree Know-It-All
ASP Free Novice (500 - 999 posts)
 
Join Date: Aug 2004
Posts: 931 asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 16 h 6 sec
Reputation Power: 325
I'm not familiar with the particulars of DB2, but it seems like your question is in regard to standard SQL

So unless DB2 isn't following standards, here you go:

The IN is used to check for a list of values, whereas the = checks for only 1 value
SELECT CUSNO WHERE CUSNO = 150
SELECT CUSNO WHERE CUSNO IN (150, 151, 160, 215, 35000)

The quotes are used to specify a string value. Numbers don't require the quotes, but strings do
SELECT CUSNO WHERE CUSNO = 150
SELECT CUSNO WHERE LNAME = 'Smith'
SELECT CUSNO WHERE LNAME IN ('Smith', 'Jones', 'Wakefield')

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > which to use: LIKE, =, IN... help!!!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT