|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! |
|
#2
|
|||
|
|||
|
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') |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > which to use: LIKE, =, IN... help!!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|