SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Evangelist Miguel61's Avatar
    Join Date
    Mar 2008
    Posts
    402
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Problem with Concat Function

    Hi there.

    I can not working this CONCAT Function:

    Code:
    CONCAT
       (
          SUBSTRING_INDEX(`ab00-1-380216`,'-',1)
        , SUBSTRING_INDEX(REVERSE(`ab00-1-380216`),'-',1)
       )
    The input: ab00-1-380216
    The output correct: ab00138216

    I have this output incorrect: ab00612083

    Can u help me?

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Code:
    CONCAT
       (
          SUBSTRING_INDEX(`ab00-1-380216`,'-',1)
        , SUBSTRING_INDEX(`ab00-1-380216`,'-',-1)
       )
    MySQL :: MySQL 5.1 Reference Manual :: 11.5 String Functions

  3. #3
    SitePoint Evangelist Miguel61's Avatar
    Join Date
    Mar 2008
    Posts
    402
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Thanks Sir.

    Your output is: ab00380216.

    I need this output: ab00138216

    Add 1 value before 4 caracters of the string, delete 0 value in the seven position of the string... it's possible?

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    So what you want is the string without the two '-' ?
    Try replace

  5. #5
    SitePoint Evangelist Miguel61's Avatar
    Join Date
    Mar 2008
    Posts
    402
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    So what you want is the string without the two '-' ?
    Try replace
    Thanks Sir.

    In the u suggestion already deleted '-' in the string.

    The input: ab00-1-380216
    Your output: ab00 380 216

    My output: ab00 (Add 1) 38 (Delete 0) 216
    ab00 1 38 216

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Miguel61 View Post
    Thanks Sir.

    In the u suggestion already deleted '-' in the string.

    The input: ab00-1-380216
    Your output: ab00 380 216

    My output: ab00 (Add 1) 38 (Delete 0) 216
    ab00 1 38 216
    You're welcome. Forget about SUBSTRING_INDEX. Use replace on the original string, replacing '-' with ''.

  7. #7
    SitePoint Evangelist Miguel61's Avatar
    Join Date
    Mar 2008
    Posts
    402
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    You're welcome. Forget about SUBSTRING_INDEX. Use replace on the original string, replacing '-' with ''.
    Thanks Sir.

    I try this:

    PHP Code:
    SELECT
    REPLACE
    (CONCAT
       
    (
          
    SUBSTRING_INDEX('ab00-1-380216','-',1)
        , 
    SUBSTRING_INDEX('ab00-1-380216','-',-1
       ), 
    '-'''
    The output: ab00380216

    Now I need this output: ab00138216

  8. #8
    SitePoint Evangelist Miguel61's Avatar
    Join Date
    Mar 2008
    Posts
    402
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    I try this:

    PHP Code:
    SELECT
    REPLACE
    (CONCAT
       
    (
          
    SUBSTRING_INDEX('ab00-1-380216','-',2)
        , 
    SUBSTRING_INDEX('ab00-1-380216','-',-1
       ), 
    '-'''A
    The output: ab001380216

    Now I need this output: ab00138216

    I need delete this 0 value... ab00 138 [0] 216

  9. #9
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by guido2004 View Post
    You're welcome. Forget about SUBSTRING_INDEX. Use replace on the original string, replacing '-' with ''.
    Do NOT use SUBSTRING_INDEX!
    Don't use REPLACE with SUBSTRING_INDEX.
    Use only REPLACE.

    Ahh, I didn't see that '0' that has to go... hmm, is it always in the same position?

  10. #10
    SitePoint Evangelist Miguel61's Avatar
    Join Date
    Mar 2008
    Posts
    402
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Thanks Sir.


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
  •