Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate Numbers in sqlite as text with a dash character

I am trying to concatenate numbers as text, with a dash (-) between the numbers I am concatenating.

I have figured out how to concatenate numbers as text:

CAST(variable1 AS VARCAHR) || CAST(variable2 AS VARCHAR)

I would like a dash between these, i.e.

CAST(variable1 AS VARCAHR) || CAST(- AS VARCHAR) || CAST(variable2 AS VARCHAR)

but this gives me an invalid SQL error. I think it might have something to do with the dash not being in unicode or something, I am not sure. Thank you for your help.

like image 518
Chad Crowe Avatar asked Oct 16 '25 11:10

Chad Crowe


1 Answers

Just concat it with a literal string (also you don't need the casts):

variable1 || '-' || variable2
like image 189
Colonel Thirty Two Avatar answered Oct 19 '25 05:10

Colonel Thirty Two



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!