1

I am having trouble using the concat() function in MySQL to create a string that displays a date. The issue appears to be with passing a variable or function to the concat function.

SELECT client.client_name AS Client Name
   , month(curdate()) AS exp1
   , concat('2012/' , '5' , '/' , '6') AS exp2 
   , concat('2012' , '/' , month(curdate())) AS exp3
   , concat('2012/' , client.start_day_of_month) AS exp4
FROM client
GROUP BY client.client_name

The results show as follows:

Client Name |  exp1 | exp2       | exp3    |    exp4
Client A    |   10  |   2012/5/6 |    BLOB |     BLOB

I am not able to get the concat() to work with exp3 and exp4:

   concat('2012' , '/' , month(curdate())) AS exp3
   concat('2012/' , client.start_day_of_month) AS exp4 

I think this is due to passing the function or variable to concat(), but I can't figure out how to get it to work properly. I've tried all types of syntax/quotes but can't seem to figure out the issue.

1 Answer 1

1

Try it by casting

 CAST(month(curdate()) AS CHAR(25))
Sign up to request clarification or add additional context in comments.

3 Comments

where would I do that within the statement?
inside concat, concat('2012' , '/' , CAST(month(curdate()) AS VARCHAR(25))) AS exp3
sorry it's not VARCHAR but rather it's CHAR

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.