Concat syntax

Hello guys!

I can not get the output 201101 with this query in MySql:

mysql> SELECT MAKEDATE(YEAR(CURDATE())-1,1) input
      ,CONCAT(YEAR(MAKEDATE(YEAR(CURDATE())-1,1)),MONTH(MAKEDATE(YEAR(CURDATE())-1,1))) output;

+------------+--------+
| input      | output |
+------------+--------+
| 2011-01-01 | 20111  |
+------------+--------+
1 row in set

I hope your help.
Saludos! :slight_smile:

that’s because MONTH returns an integer, i.e. 1

the thing that puzzles me is how come you go through the MAKEDATE business if all you want is last year

try this –

SELECT YEAR(CURRENT_DATE)-1 AS input 
     , CONCAT(YEAR(CURRENT_DATE)-1 , '01' )

thank you very much for your reply.

mysql> SELECT YEAR(CURRENT_DATE)-1 AS input
     , CONCAT(YEAR(CURRENT_DATE)-1 , '01' );

+-------+--------------------------------------+
| input | CONCAT(YEAR(CURRENT_DATE)-1 , '01' ) |
+-------+--------------------------------------+
|  2011 | 201101                               |
+-------+--------------------------------------+
1 row in set

I use

SELECT MAKEDATE(YEAR(CURDATE()) - 1, 1) 

because I need always the first day of previous year.

Sql CONCAT() function is used to concatenate two or more strings.MySQL allows you concatenate more than two strings while other force exactly two.

Syntax:
Concat(string1,string2)

what???!!!

perhaps you could explain what this means