Reputation: 6461
I want to select the value birthday from my database table. If it is not null the output should be a date. But if it is null, then the output should be empty.
'SELECT *,
case when isnull(mydate) then null else date_format(mydate, cats.bithday,"%d.%m.%y") end as birthday;
FROM cats
LEFT JOIN dogs ON cats.dogs=dogs.id'
I get an error:
Syntax error or access violation: 1582 Incorrect parameter count in the call to native function 'date_format'
Upvotes: 0
Views: 576
Reputation: 1248
SELECT *, ifnull(cats.bithday,'') as cats_birthday
FROM cats
LEFT JOIN dogs ON cats.dogs=dogs.id
Result:
case (birthday is null)
cats_birthday = ''
case (birthday is not null)
cats_birthday = db-value
Upvotes: 3
Reputation: 12548
You are giving date_format three parameters, but it only expects two.
See the MySQL docs here
DATE_FORMAT(date,format)
Upvotes: 0