I get the following error when I attempt to create dynamic columns. I thought this was legit, but apparently Android and SQLite don't like this. I'm sure I'm missing something simple, but I just can't recall.
Error message is: no such column: sundayResult: , while compiling:
CREATE TABLE DAYSUSED(
_id INTEGER PRIMARY KEY autoincrement,
sunday INTEGER NOT NULL,
monday INTEGER NOT NULL,
tuesday INTEGER NOT NULL,
wednesday INTEGER NOT NULL,
thursday INTEGER NOT NULL,
friday INTEGER NOT NULL,
saturday INTEGER NOT NULL);
SELECT _id
, volume_level
, vibrate
, CASE WHEN sunday = 1 THEN 'Sun' ELSE ' ' END AS sundayResult
, CASE WHEN monday = 1 THEN 'Mon' ELSE ' ' E开发者_如何学GoND AS mondayResult
, CASE WHEN tuesday = 1 THEN 'Tues' ELSE ' ' END AS tuesdayResult
, CASE WHEN wednesday = 1 THEN 'Wed' ELSE ' ' END AS wednesdayResult
, CASE WHEN thursday = 1 THEN 'Thur' ELSE ' ' END AS thursdayResult
, CASE WHEN friday = 1 THEN 'Fri' ELSE ' ' END AS fridayResult
, CASE WHEN saturday = 1 THEN 'Sat' ELSE ' ' END AS saturdayResult
, sundayResult || ' ' || mondayResult || ' ' || tuesdayResult || ' ' || wednesdayResult || ' ' || thursdayResult || ' ' || fridayResult || ' ' || saturdayResult || ' ' AS days_of_week
FROM DAYSUSED
The last line will work if I do a direct call to the actual columns like:
, sunday || ' ' ||
instead of what I have currently which is:
, sundayResult || ' ' ||
I've looked all over and don't know what else to try, as I'd really like to alter the data for the cursor.
Thanks, Kelly
sundayResult is just an alias and you cannot use it into the same query. You need something like this. If volume_level and vibrate are coming from different table, then join it with subquery "days"
SELECT _id
, volume_level
, vibrate
, days.sundayResult || ' ' || days.mondayResult || ' ' || days.tuesdayResult || ' ' || days.wednesdayResult || ' ' || days.thursdayResult || ' ' || days.fridayResult || ' ' || days.saturdayResult || ' ' AS days_of_week
from
( select
CASE WHEN sunday = 1 THEN 'Sun' ELSE ' ' END AS sundayResult
, CASE WHEN monday = 1 THEN 'Mon' ELSE ' ' END AS mondayResult
, CASE WHEN tuesday = 1 THEN 'Tues' ELSE ' ' END AS tuesdayResult
, CASE WHEN wednesday = 1 THEN 'Wed' ELSE ' ' END AS wednesdayResult
, CASE WHEN thursday = 1 THEN 'Thur' ELSE ' ' END AS thursdayResult
, CASE WHEN friday = 1 THEN 'Fri' ELSE ' ' END AS fridayResult
, CASE WHEN saturday = 1 THEN 'Sat' ELSE ' ' END AS saturdayResult
FROM DAYSUSED
) days
精彩评论