Link to home
Create AccountLog in
Avatar of Dmon443
Dmon443

asked on

SQL command syntax

I am having trouble with a SQL command in Delphi 2010, I think I have the syntax wrong...here is what I have
dmoLibrary.sdsBook.CommandText := 'SELECT * from librarybook '+
                                    'WHERE BookCategory = ''Fantasy'''+
                                    'ORDER BY BookTitle';
that gives error:
Project raised exception class TDBXError with message 'Column unknown BOOKTITLE'.
Avatar of awking00
awking00
Flag of United States of America image

Can you describe the librarybook table?
SOLUTION
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Ensure you have a BookTitle column in librarybook  table.
Avatar of Dmon443
Dmon443

ASKER

ok now it looks like this:
dmoLibrary.sdsBook.CommandText := 'SELECT * from librarybook '+
                                    'WHERE BookCategory = '+ QuotedStr('Fantasy')+
                                    ' ORDER BY Book Title';

I had a look at the table and it is named "Book Title" 2 words. But now I still get an error:
First chance exception at $7542C41F. Exception class TDBXError with message
'Token unknown - line 1, char 71
Title'.
try putting double quotes around the column name in the ORDER BY clause:

dmoLibrary.sdsBook.CommandText := 'SELECT * from librarybook '+
                                    'WHERE BookCategory = '+ QuotedStr('Fantasy')+
                                    ' ORDER BY "Book Title"';
alternatively instead of using * in the select statement for the columns to retrieve specify the columns and use an alias for the column Book Title so there is no space in the name.

eg:

dmoLibrary.sdsBook.CommandText := 'SELECT BookId, BookCategory, Book Title as BookTitle from librarybook '+
                                    'WHERE BookCategory = '+ QuotedStr('Fantasy')+
                                    ' ORDER BY BookTitle';
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Both would have been required.
Avatar of Dmon443

ASKER

solved the problem