Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2004
    Posts
    25

    Unanswered: 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

  2. #2
    Join Date
    Feb 2002
    Location
    Germany
    Posts
    141
    You must check with

    WHERE accountno LIKE '0134%'
    Rodney Krick

  3. #3
    Join Date
    Mar 2004
    Location
    Toronto, ON, Canada
    Posts
    513
    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

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    if accountno were really an integer, would it have those leading zeroes?

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Mar 2004
    Location
    Toronto, ON, Canada
    Posts
    513
    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

  6. #6
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    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'

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    what is it with all the toronto people posting in this thread???

    where's HomerBoo?

    we should start our own local database club, eh
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •