How to check a condition on SELECT statement
Posted on 2011-04-29
In an SQL query statement which I'm sending to a remote machine I have:
SELECT field1, field2, field3, .... FROM table and ....
However, database designer explained that field1 and field2 together are part number (together) so I used CONCAT() function to deal with that piece of information as a whole meaning that:
SELECT CONCAT(CONCAT(field1,'-'), field2), field3, .... FROM table
So if the data is 2 and 1234-5678 becomes 2-1234-5678
Or if 18 and 1234-5678 becomes 18-1234-5678
Now, I need to add '0' to field if it is less than 10 and show it and store it in a 2nd database as 02-1234-5678. Which function can I use in an SQL statement to check the length of field1 and add a zero on the fly?