I have three columns in an sqlite table:
Column1 Column2 Column3
A 1 1
A 1 2
A 12 2
C 13 2
B 11 2
I need to select Column1-Column2-Column3
(e.g. A-01-0001
). I want to pad each column with a -
I am a beginner with regards to SQLite, any help would be appreciated
Just one more line for @tofutim answer ... if you want custom field name for concatenated row ...
Tested on SQLite 3.8.8.3, Thanks!
SQLite has a
printf
function which does exactly that:From http://www.sqlite.org/lang_expr.html
For padding, the seemingly-cheater way I've used is to start with your target string, say '0000', concatenate '0000423', then substr(result, -4, 4) for '0423'.
Update: Looks like there is no native implementation of "lpad" or "rpad" in SQLite, but you can follow along (basically what I proposed) here: http://verysimple.com/2010/01/12/sqlite-lpad-rpad-function/
Here's how it looks:
it yields