Selective concat in query?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cubix
    New Member
    • Jun 2008
    • 2

    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?
  • cubix
    New Member
    • Jun 2008
    • 2

    #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

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Use the IFNULL function.

      Comment

      Working...