I'm backing up MySql -table to worksheet. My current result-set has rows where some of columns are empty.
That's ok, but for the worksheet i need these to be replaced with 'foo'. HowTo?
All help is highly appreciated.
I'm backing up MySql -table to worksheet. My current result-set has rows where some of columns are empty.
That's ok, but for the worksheet i need these to be replaced with 'foo'. HowTo?
All help is highly appreciated.
Empty or NULL? There's a big difference there. If it's NULL, you can use the COALESCE()
function:
SELECT COALESCE(`MyColumn`, 'foo') As MyColumn FROM `MyTable`
If the value is only empty, you need to do something more like this:
SELECT IF(char_length(`MyColumn`)>0, `MyColumn`, 'foo') AS MyColumn FROM `MyTable
Or you can even combine them:
SELECT IF(char_length(COALESCE(`MyColumn`,''))>0,`MyColumn`,'foo') AS MyColumn FROM `MyTable`
The COALESCE
statement returns the first non-null parameter that it is passed:
SELECT COALESCE(column,'foo')
Returns column
if it isn't null, 'foo'
otherwise.