SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    select 1st few characters

    hello,
    how do i select the first few characters of a row
    e.g first 3 characters

    thanks
    Afrika

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    SQL Server/Access:
    Code:
    SELECT LEFT(yourfield, 3) FROM table;
    MySQL:
    Code:
    SELECT SUBSTRING(yourfield, 0, 3) FROM table;

  3. #3
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh ok, Thanks Vinnie
    its actually MS SQL server

    rgds
    Afrika

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,216
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    sorry, vinnie, SUBSTRING starts at 1, not 0

    also, LEFT(yourfield,3) works in mysql too

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by r937
    sorry, vinnie, SUBSTRING starts at 1, not 0


Bookmarks

Posting Permissions

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