SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 26
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to take the first letter and insert it in another field

    Hello everybody, I am trying to insert in the letter field the first letter of the FILEDX's content, How can i do it???

    Any ideas is most appreciated, thanks


  2. #2
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Check out Substr/substring()
    Ryan B | My Blog | Twitter

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your swift reply rguy84, i will check it now

  4. #4
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    this will chop the strings up, you'll still have to insert them.
    Ryan B | My Blog | Twitter

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you are right, but when i chop the characters and get, how can i deal with it to insert it in the second field, please if you have idea

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT SUBSTRING('artist_name',1,1) this is it what i was looking, now i will try to find out how to insert it into the second field, if you have any idea while mine goes well its most appreciated, with lots of thanks

  7. #7
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Try
    Code MySQL:
    INSERT INTO tabl_name('firstLetter')
    VALUES (
     SELECT (SUBTRING('artist_name',1,1))
    )
    Ryan B | My Blog | Twitter

  8. #8
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks,Yes infact this worked with me too

    insert into tbl1 (letter)
    SELECT SUBSTRING('field',1,1)
    from tbl2

    But now i will do compare using where field's ID = same ID to be inserted respectively

  9. #9
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And also i want to use UPDATE instead of insert because some fields contains some data, hope if you have any suggestions, with my infinite thanks

  10. #10
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Code:
    UPDATE table
    SET letter = SUBSTRING(field, 1, 1)

  11. #11
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,336
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by hoverinc View Post
    Hello everybody, I am trying to insert in the letter field the first letter of the FILEDX's content, How can i do it???
    i should think that a relatively germane question is why would you want to do that?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  12. #12
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also i have checked this one it works


    SELECT LEFT(FIELD, 1)FROM TABLE

  13. #13
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    UPDATE TABLE
    SET letter = SUBSTRING(FIELD, 1, 1)
    where id=id2

    With this we did it, same thanks to all of you guys for today we have solved our problem and we achieved our duty... thanks AGAIN

  14. #14
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Code:
    UPDATE table
    SET letter = SUBSTRING(field, 1, 1)

    Thanks so much, that helped me lot

  15. #15
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    i should think that a relatively germane question is why would you want to do that?
    Yes because I was in a need to put that first letter in a field that was requesting the letter

  16. #16
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,336
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    why would you want to have a separate column containing the first letter only?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  17. #17
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    homework?

  18. #18
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    why would you want to have a separate column containing the first letter only?
    Well you're right, this letter appears when its categorized by letters

  19. #19
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    So why don't you group them by distinct values of the results dynamically.
    Ex: You have the results Ryan, Rudy, Guido. I am assuming you want like a a-z list. Currently you'd get R,R,G, which R, G would be cleaner.
    Ryan B | My Blog | Twitter

  20. #20
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rguy84 View Post
    So why don't you group them by distinct values of the results dynamically.
    Ex: You have the results Ryan, Rudy, Guido. I am assuming you want like a a-z list. Currently you'd get R,R,G, which R, G would be cleaner.
    It's not working in this manner, only this field should appear with a letter, that was the aim

  21. #21
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now if i want to use this code it is giving error, please need your attention with this dear guys

    DELETE * fromTABLE WHERE catid !='40'
    because i want to delete all records except who have catid 40

    With thanks

  22. #22
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,336
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    what is the exact error you got?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  23. #23
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    what is the exact error you got?

    No errors, just i have a category want to keep it

  24. #24
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,336
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    didn't you just say "Now if i want to use this code it is giving error" ???
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  25. #25
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Think it is an english mixup Rudy. Think he meant will it give one or what would happen if i ran it.
    Ryan B | My Blog | Twitter


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
  •