472,146 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

Selective concat in query?

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
2 1708
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
13,262 8TB
Use the IFNULL function.
Jun 9 '08 #3

Post your reply

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

Similar topics

2 posts views Thread by delgados129 | last post: by
8 posts views Thread by May | last post: by
reply views Thread by Roy | last post: by
3 posts views Thread by nickdevx | last post: by
4 posts views Thread by Martin Evans | last post: by
17 posts views Thread by ramadu | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.