String concatenation does not work in SQLite

SqlSqliteStringOperatorsConcatenation

Sql Problem Overview


I am trying to execute a SQlite replace function, but use another field in the function.

select  locationname + '<p>' from location;

In this snip, the result is a list of 0s. I would have expected a string with the text from locationname and the '<p>' literals.

Sql Solutions


Solution 1 - Sql

Try using || in place of +

select  locationname || '<p>' from location;

From SQLite documentation:

>The || operator is "concatenate" - it joins together the two strings of its operands.

Solution 2 - Sql

The || operator is the concatenation in SQLite. Use this code:

select  locationname || '<p>' from location;

Solution 3 - Sql

For comparison,

SQLite                      ||
Oracle CONCAT(string1, string2) or || MySQL CONCAT(string1, string2, string3...) or || if PIPES_AS_CONCAT enabled Postgres CONCAT(string1, string2, string3...) or || Microsoft SQL Server 2012+ CONCAT(string1, string2, string3...) or + Microsoft Access +

Solution 4 - Sql

for Visual Studio 2010, using the Data Sources designer or wizard, you're in trouble using || operator. Create a view in the sqlite db and create your data source(s) from that.

See also this thread.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIan VinkView Question on Stackoverflow
Solution 1 - SqlcodaddictView Answer on Stackoverflow
Solution 2 - SqlshamittomarView Answer on Stackoverflow
Solution 3 - SqlBrian BurnsView Answer on Stackoverflow
Solution 4 - SqlquickdrawView Answer on Stackoverflow