SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Jul 2002
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help w/ TRIM( string, please

    I have some headlines stored in a column named "HEADLINE" in a table named "STORIES." The headlines all start with one of the following three prefixes:

    Interview:
    Album Review:
    Live Review:

    I want to remove the "Interview:" prefix from stories of TYPE "interview", "Album Review:" from stories of TYPE "album review" and "Live Review:" from stories of TYPE "live review."

    As far as I can tell, I need to do a query using a TRIM command, but I can't figure out exactly how to format the query. Can someone please help? Thanks.

    -JZ

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    no, trim removes spaces

    you want a substring function, and perhaps a length function as well

    since these vary between databases, it will help to know which database you're on

    it will be something like

    update stories
    set headline
    = substr(headline,12,len(headline)-12)
    where substr(headline,1,11) = 'Interview: '

    repeat for the other two strings, adjusting byte positions as required

  3. #3
    SitePoint Addict
    Join Date
    Jul 2002
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops. Sorry 'bout that. I'm using an SQL DB.

    I wasn't able to successfully execute the query that you typed above.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    what kind of "SQL" database?

    microsoft sql/server? sybase sql/server? mysql? postgresql?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Addict
    Join Date
    Jul 2002
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    MySQL

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    ah, that's different then, innit

    update stories
    set headline
    = substring(headline from 12)
    where left(headline,11) = 'Interview: '

    see
    6.3.2 String Functions

    rudy


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
  •