25

I have a table with this data

id , name    , description
1  , apple   , ''
2  , orange  , ''

I am trying to pass the following statement to update the row so the description column is 'desc of apple' and 'desc of orange' but it is not working.

 Update TestTable Set description = 'desc of ' + name 

What is the proper syntax to concatenate strings?

CJBS
  • 15,147
  • 6
  • 86
  • 135
Snowy
  • 5,942
  • 19
  • 65
  • 119

1 Answers1

69

SQLite's string concatenation operator is "||", not "+"

UPDATE TestTable SET description = 'desc of ' || name;
Ben S
  • 68,394
  • 30
  • 171
  • 212
  • + is not standard SQL syntax for string concatenation. – Ned Batchelder Sep 18 '09 at 18:32
  • 9
    Is there a standard SQL Syntax for string concatenation? It seems every DB uses a different one. MySQL Uses Concat() function, SQL Lite using ||, SQL Server Uses +. Definitely something that should be standardized. – Kibbee Sep 18 '09 at 18:45
  • 1
    Yes, there is a standard SQL syntax. It is `||`, [adopted](https://books.google.com/books?id=6jqZExL6UGcC&pg=PA106&dq=concatenation+infixed+operator&hl=en&sa=X#v=onepage) in the [SQL-92 standard ISO/IEC 9075:1992](https://www.google.com/search?sclient=psy-ab&biw=1920&bih=979&q=%22concatenation+operator%22+ISO%2FIEC+9075:1992+X3H2-92-154+%22double+period%22). It's just that SQL Server and MySQL chose not to comply with the standard. Although MySQL can be coaxed by setting [`PIPES_AS_CONCAT`](http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_pipes_as_concat) – Amit Naidu Mar 06 '16 at 04:15