Page 1 of 1

Using CASE statement in a SELECT

Posted: Mon 19 Aug 2013 14:39
by Ken McClain
I'm having a problem getting the data from the following SQL CASE statement to show
properly in a TDBGrid:

SELECT Stamp,CatID,
(CASE WHEN CatID = 0 THEN 'Info'
WHEN CatID = 1 THEN 'Warning'
WHEN CatID = 2 THEN 'Error'
WHEN CatID = 3 THEN 'Debug'
END) AS Category,
Message
FROM LogEntries

Problem: The newly created field 'Category' displays '(MEMO)' for its data
rather than the text.

Displays properly when run using 'SQLite Expert'

Any ideas?
Thanks

Re: Using CASE statement in a SELECT

Posted: Mon 19 Aug 2013 14:47
by AlexP
Hello,

When using the CASE construction,aggregate functions, etc., SQLite returns field type as Unknown, since it cannot define the result field type, therefore we map such fields as TMemoField. To solve the problem, you can use the Data Type Mapping technology in order to explicitly specify the type, to which such fields should be mapped for DataSet

Re: Using CASE statement in a SELECT

Posted: Mon 19 Aug 2013 18:45
by Ken McClain
Thank you. That did it.

Re: Using CASE statement in a SELECT

Posted: Tue 20 Aug 2013 07:06
by AlexP
Hello,

Glad to see that the problem was solved. If you have any other questions, feel free to contact us.