vendredi 14 août 2015

I need to format a column value in my return but that column may not exist in which case I need to grab the rest of the columns data

I have an app that uses a local sqlite database which has a particular table called 'Theme' for each project. Sometimes that table has a column 'startDate' and sometimes it does not. I need to have that 'startDate' returned in a particular format if it does exist. My problem is, when I query this table, specifying the neccessary format, if the column does not exist, the query returns an error "NO SUCH COLUMN". HOW DO I CHECK FOR COLUMN EXISTENCE, IF IT DOES EXIST, RETURN THE 'startDate' PROPERLY FORMATTED ALONG WITH THE REST OF THE DATA, IF IT DOES NOT EXIST, RETURN THE REST OF THE DATA WITHOUT THE 'startDate'???

Something like this...

SELECT *  (if exists STRFTIME('%Y/%m/%d %H:%M:%S', startDate) AS sDate FROM Theme 

Aucun commentaire:

Enregistrer un commentaire