If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Partial Number Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-07-04, 01:36
Shinto Shinto is offline
Registered User
 
Join Date: Jan 2004
Posts: 25
Partial Number Search

I have the following table and columns.


Account

AccountNo(Integer) AccountID(VarChar)
----------------------------------------------------
0134707 John
0134570 Perry
0134752 Koala



Is there any SQL query for me to select AccountNos which begin with '0134'? i tried using the Select * from account where accountno = %0134% but it didnt work. Thanks for your help
Reply With Quote
  #2 (permalink)  
Old 04-07-04, 02:11
RKrick RKrick is offline
Registered User
 
Join Date: Feb 2002
Location: Germany
Posts: 141
You must check with

WHERE accountno LIKE '0134%'
__________________
Rodney Krick
Reply With Quote
  #3 (permalink)  
Old 04-07-04, 08:09
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally posted by RKrick
You must check with

WHERE accountno LIKE '0134%'
You need to cast it though... it's an INTEGER.

WHERE char(accountno) LIKE '01234%'
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #4 (permalink)  
Old 04-07-04, 08:24
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
if accountno were really an integer, would it have those leading zeroes?

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 04-07-04, 08:32
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally posted by r937
if accountno were really an integer, would it have those leading zeroes?

But if it isn't, then would he have put (Integer) next to the column name?

We'll never know!
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #6 (permalink)  
Old 04-07-04, 09:18
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally posted by J Petruk
But if it isn't, then would he have put (Integer) next to the column name?

We'll never know!
..and if it really is an integer I believe it might be more efficient to search for 'ACCOUNTNO BETWEEN 134000 AND 134999'
Reply With Quote
  #7 (permalink)  
Old 04-07-04, 09:34
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
what is it with all the toronto people posting in this thread???

where's HomerBoo?

we should start our own local database club, eh
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On