I have a table like the following :
code ---> INTEGER
name ---> CHAR
+------+------+
| code | name |
+------+------+
| 1 | aa |
| 2 | bb |
| 3 | cc |
I want to pad with left zeros the code field in this way :
SELECT LPAD(code,5,'0') FROM table;
This query works well in MySQL but it doesn’t work on SQL Server and on PostgreSQL, i’m looking for a query that work on all databases or at least on these four :
- MySQL
- PostgreSQL
- MSSQL
- Firebird
without any changes . Is there a solution ?
The correct answer is “do this in your client”.
There is no single solution at the RDBMS level
However, for SQL Server 2012 (yes, next release), PostgreSQL and MySQL you can do this: