Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,108
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Way to replace Long Function Call in SELECT??

    Is there some way I can clean up the query below by not having to repeat my long, nested Function calls in the SELECT statement??

    Code:
    SELECT pm.id, pm.sender_flag,
    	IF(CHAR_LENGTH(GROUP_CONCAT(m_to.username ORDER BY r.blind_copy ASC, m_to.username SEPARATOR ', ')) < '40',
    			GROUP_CONCAT(m_to.username ORDER BY r.blind_copy ASC, m_to.username SEPARATOR ', '),
    			CONCAT(SUBSTRING(GROUP_CONCAT(m_to.username ORDER BY r.blind_copy ASC, m_to.username SEPARATOR ', ') , 1, 40), '...')) AS recipients,
    Sincerely,


    Debbie

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts
    User variable. Not tested, I think mysql specific, out of head.
    Code:
    SELECT pm.id, pm.sender_flag,@t4 := (GROUP_CONCAT(m_to.username ORDER BY r.blind_copy ASC, m_to.username SEPARATOR ', '),
    	IF(CHAR_LENGTH (@t4) < '40',
    		       (@t4),
          CONCAT(SUBSTRING (@t4) , 1, 40), '...')) AS recipients, ...
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search


  •  

    Posting Permissions

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