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.Command Text := 'SELECT * from librarybook '+
'WHERE BookCategory = ''Fantasy'''+
'ORDER BY BookTitle';
that gives error:
Project raised exception class TDBXError with message 'Column unknown BOOKTITLE'.
dmoLibrary.sdsBook.Command
'WHERE BookCategory = ''Fantasy'''+
'ORDER BY BookTitle';
that gives error:
Project raised exception class TDBXError with message 'Column unknown BOOKTITLE'.
Can you describe the librarybook table?
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
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.
ASKER
ok now it looks like this:
dmoLibrary.sdsBook.Command Text := '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'.
dmoLibrary.sdsBook.Command
'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.Command Text := 'SELECT * from librarybook '+
'WHERE BookCategory = '+ QuotedStr('Fantasy')+
' ORDER BY "Book Title"';
dmoLibrary.sdsBook.Command
'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.Command Text := 'SELECT BookId, BookCategory, Book Title as BookTitle from librarybook '+
'WHERE BookCategory = '+ QuotedStr('Fantasy')+
' ORDER BY BookTitle';
eg:
dmoLibrary.sdsBook.Command
'WHERE BookCategory = '+ QuotedStr('Fantasy')+
' ORDER BY BookTitle';
ASKER CERTIFIED SOLUTION
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.
ASKER
solved the problem