SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Concat syntax

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

    Concat syntax

    Hello guys!

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

    Code:
    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!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,021
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    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 --
    Code:
    SELECT YEAR(CURRENT_DATE)-1 AS input 
         , CONCAT(YEAR(CURRENT_DATE)-1 , '01' )
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist Miguel61's Avatar
    Join Date
    Mar 2008
    Posts
    402
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    thank you very much for your reply.

    Code:
    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
    Code:
    SELECT MAKEDATE(YEAR(CURDATE()) - 1, 1)
    because I need always the first day of previous year.

  4. #4
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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)

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,021
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by GireeshS View Post
    ...while other force exactly two.
    what???!!!

    perhaps you could explain what this means
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •