By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,182 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

Selective concat in query?

P: 2
I'm trying to run a query in MySQL Query Browser that will concat 3 fields together to form a single date format. This part I don't have a problem with:

SELECT CONCAT(`Field12`, '/', `Field13`, '/', `Field11`) FROM `mini`;

However, not all rows have these fields filled, and I end up with / / in the result. I would like to do something such as

SELECT IF(`Field12` IS NOT NULL THEN CONCAT(`Field12`, '/', `Field13`, '/', `Field11`) ELSE ' ') FROM 'mini';

Any way to get this working properly?
Jun 6 '08 #1
Share this Question
Share on Google+
2 Replies

P: 2
Just to clarify, I still want the blank row, this is only a snippet of a much larger query that converts and entire flat table into a different format.

I did manage to achieve the a almost perfect result with

SELECT date_format(str_to_date(CONCAT(`Field12`, `Field13`, `Field11`), "%m%d%Y"), "%m/%d/%Y")FROM `mini`;

seems very redundant :-D
And now I get NULL in my results
Jun 6 '08 #2

P: 13,264
Use the IFNULL function.
Jun 9 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.