Nested Concatenations in Beast Mode

Whenever we use nested Concatenations with Case Statements, every Concatenations gives a break line.

How to avoid that ?

 

 

 

CONCAT(
'Last Week SEO had ',

ROUND(SUM(CASE WHEN WEEK(DATE_SUB(`Date`,1)) = WEEK(DATE_SUB(CURRENT_DATE(),7)) and YEAR(`Date`) = YEAR(CURDATE()) and `Tracking Code Program` = 'SEO' and `API Name` = 'Adobe Rev'
THEN `Visits` END)),

' Visits, which was ',

ABS(ROUND(((ROUND(SUM(CASE WHEN WEEK(DATE_SUB(`Date`,1)) = WEEK(DATE_SUB(CURRENT_DATE(),7)) and YEAR(`Date`) = YEAR(CURDATE()) and `Tracking Code Program` = 'SEO' and `API Name` = 'Adobe Rev'
THEN `Visits` END))
-
ROUND(SUM(CASE WHEN WEEK(DATE_SUB(`Date`,-6)) = WEEK(DATE_SUB(CURRENT_DATE(),7)) and YEAR(`Date`) = YEAR(CURDATE()) and `Tracking Code Program` = 'SEO' and `API Name` = 'Adobe Rev'
THEN `Visits` END)))
/
ROUND(SUM(CASE WHEN WEEK(DATE_SUB(`Date`,-6)) = WEEK(DATE_SUB(CURRENT_DATE(),7)) and YEAR(`Date`) = YEAR(CURDATE()) and `Tracking Code Program` = 'SEO' and `API Name` = 'Adobe Rev'
THEN `Visits` END)))*100)),

'% ',

CASE WHEN
(((ROUND(SUM(CASE WHEN WEEK(DATE_SUB(`Date`,1)) = WEEK(DATE_SUB(CURRENT_DATE(),7)) and YEAR(`Date`) = YEAR(CURDATE()) and `Tracking Code Program` = 'SEO' and `API Name` = 'Adobe Rev'
THEN `Visits` END))
-
ROUND(SUM(CASE WHEN WEEK(DATE_SUB(`Date`,-6)) = WEEK(DATE_SUB(CURRENT_DATE(),7)) and YEAR(`Date`) = YEAR(CURDATE()) and `Tracking Code Program` = 'SEO' and `API Name` = 'Adobe Rev'
THEN `Visits` END)))
/
ROUND(SUM(CASE WHEN WEEK(DATE_SUB(`Date`,-6)) = WEEK(DATE_SUB(CURRENT_DATE(),7)) and YEAR(`Date`) = YEAR(CURDATE()) and `Tracking Code Program` = 'SEO' and `API Name` = 'Adobe Rev'
THEN `Visits` END)))*100) > 0
THEN CONCAT('<div style="color:#228B22">',' increase WoW ','</div>') ELSE CONCAT('<div style="color:#ff0000">',' decrease WoW ','</div>') END,

(CASE when
(
(((ROUND(SUM(CASE WHEN WEEK(DATE_SUB(`Date`,1)) = WEEK(DATE_SUB(CURRENT_DATE(),7)) and YEAR(`Date`) = YEAR(CURDATE()) and `Tracking Code Program` = 'SEO' and `API Name` = 'Adobe Rev'
THEN `Visits`END))
)
-
(
ROUND(SUM(CASE WHEN WEEK(DATE_SUB(`Date`,1)) = WEEK(DATE_SUB(CURRENT_DATE(),371)) and YEAR(`Date`) = YEAR(CURDATE())-1 and `Tracking Code Program` = 'SEO' and `API Name` = 'Adobe Rev'
THEN `Visits`END))
))
/
(
ROUND(SUM(CASE WHEN WEEK(DATE_SUB(`Date`,1)) = WEEK(DATE_SUB(CURRENT_DATE(),371)) and YEAR(`Date`) = YEAR(CURDATE())-1 and `Tracking Code Program` = 'SEO' and `API Name` = 'Adobe Rev'
THEN `Visits`END)))
)*100)>0
then ', Up by ' else ', Down by' end),

'. YoY stands at ',

ROUND((((ROUND(SUM(CASE WHEN WEEK(DATE_SUB(`Date`,1)) = WEEK(DATE_SUB(CURRENT_DATE(),7)) and YEAR(`Date`) = YEAR(CURDATE()) and `Tracking Code Program` = 'SEO' and `API Name` = 'Adobe Rev'
THEN `Visits`END))
)
-
(
ROUND(SUM(CASE WHEN WEEK(DATE_SUB(`Date`,1)) = WEEK(DATE_SUB(CURRENT_DATE(),371)) and YEAR(`Date`) = YEAR(CURDATE())-1 and `Tracking Code Program` = 'SEO' and `API Name` = 'Adobe Rev'
THEN `Visits`END))
))
/
(
ROUND(SUM(CASE WHEN WEEK(DATE_SUB(`Date`,1)) = WEEK(DATE_SUB(CURRENT_DATE(),371)) and YEAR(`Date`) = YEAR(CURDATE())-1 and `Tracking Code Program` = 'SEO' and `API Name` = 'Adobe Rev'
THEN `Visits`END)))
)*100),

'%.'
)

 

Best Answers

  • dthierjung
    dthierjung Contributor
    Answer ✓

    I believe your issue is the HTML you are injecting. A <div> element will cause a "line break" to occur (not truly a line break but it comes down to the CSS styling that makes it appear as such).

     

    There are many different ways to resolve this. If you are familiar with CSS, you can add some inline styling like "style="display: inline;" into the <div>. So it would look like: 

     

    CONCAT('<div style="color:#228B22; display: inline;" >',' increase WoW ','</div>')

     

    If you aren't familiar with CSS though, you can try switching the <div> element to a <span> element.

     

    Both should work, but let me know if not.

  • Unknown
    Answer ✓

    +1 for <span> rather than <div>. I've accomplished the desired result using <span>.

     

    Thank you, @dthierjung

Answers

  • dthierjung
    dthierjung Contributor
    Answer ✓

    I believe your issue is the HTML you are injecting. A <div> element will cause a "line break" to occur (not truly a line break but it comes down to the CSS styling that makes it appear as such).

     

    There are many different ways to resolve this. If you are familiar with CSS, you can add some inline styling like "style="display: inline;" into the <div>. So it would look like: 

     

    CONCAT('<div style="color:#228B22; display: inline;" >',' increase WoW ','</div>')

     

    If you aren't familiar with CSS though, you can try switching the <div> element to a <span> element.

     

    Both should work, but let me know if not.

  • Unknown
    Answer ✓

    +1 for <span> rather than <div>. I've accomplished the desired result using <span>.

     

    Thank you, @dthierjung



  • @dthierjung @DanB  Thankyou for the quick solution. It works exactly the way i needed. <span> is the way out