cutcopypaste — 2010-04-18T17:51:12-04:00 — #1
just wondering if this is possible
say I have news_title and news_date, can I make news_title default to news_date if not entered?
this example I guess is a little more complicated because datetime has different display methods. But I'm curious to know either way.
dr_john — 2010-04-18T18:47:15-04:00 — #2
You'd have to use a trigger if you wished to make the db do this, or you could quite simply use which ever programming language you are using to check the data entered before it was sent off to the db and alter it before creating your query.
sjh — 2010-04-19T03:29:46-04:00 — #3
When selecting your data, provided that the news_title field is set to null if not specified, you can use the COALESCE function, which returns the first of its parameters which is not null.
SELECT COALESCE(news_title, news_date) AS title...