0

I am new to mysql. I am trying to combine two columns with - in between however I am getting error. If anyone could give me advice I will really appreciate it. I am getting error in this part: ,x_end_year +"-" +x_start_month+"-01",

Error Code: 1292 Truncated incorrect DOUBLE value: '-'

INSERT INTO earning (id, dateCreated, dateModified, x_t_name, x_start_date, 
                     x_end_month, x_address, x_category, x_pic, x_promo_space, 
                     x_start_month, x_space_query, x_organizer, x_end_date, 
                     x_address_query, x_current_pic, x_start_year, x_end_year,
                     x_event_title, x_pix_name),

SELECT x_idx, dateCreated, dateModified, "" , x_end_year +"-" +x_start_month+"-01",
       x_end_month, "address1", "", x_current_pic, "", x_start_month, "''", "", 
       x_end_year +"-" +x_end_month+"-01", "'address1'", x_current_pic, x_end_year, 
       x_end_year, "", ""
FROM Sale
WHERE id = 'x1'
barbsan
  • 3,418
  • 11
  • 21
  • 28
aika aika
  • 51
  • 6
  • Use `CONCAT()` for concatenating strings. It's much more reliable and readable. – TrebledJ Nov 28 '18 at 01:31
  • 1
    Possible duplicate of [String concatenation in MySQL](https://stackoverflow.com/questions/5975958/string-concatenation-in-mysql) – Nick Nov 28 '18 at 01:58
  • 4
    MySQL does not support `+` for concatenating strings. You must use `CONCAT()` or the `||` operator (if that has been enabled) – Nick Nov 28 '18 at 01:58
  • I used concat its working now thank you – aika aika Nov 28 '18 at 05:50

1 Answers1

1

You just need to use CONCAT. Here is a sample.

SELECT CONCAT (column1, column2, '-', column3, column4)
Buchiman
  • 320
  • 5
  • 18