Thread: Where Statement

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Where Statement


    Hi Everybody

    Can anyone please help me with constructing a where statement for the scenario below?

    I have a customer table with many columns one of them being an account number. The first three digits of an account number signify branch code. Now I have a branch with a branch code 235 and I want to query for a list of customer in that branch.

    How can I construct where statement that is going to read the first three digits of each account number in the customerís table and equate it to 235?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2008
    Posts
    1,928
    Rep Power
    378
    Left?
  4. #3
  5. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,173
    Rep Power
    4274
    SUBSTRING will do that, too
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    90
    Rep Power
    3
    i think what cafelatte was trying to say is something like this:
    SELECT * from customer where LEFT(account_number,3)='235'

IMN logo majestic logo threadwatch logo seochat tools logo