sql query with space in the value
How do I write where clause 开发者_Python百科where the value has spaces:
Actually I am using openJPA and I have to set parameter. The value i will be setting has a space, eg: String somevalue="firstname lastname"; query.setparameter(somevalue);
I did this but doesnot work. Any suggestion will be appreciated. Thanks.
That should work. The space within the quotes is valid. Perhaps there are spaces after the lastname, or the casing of lastname is incorrect.
That syntax does indeed work; you must be typing in a name that does not exist.
sqlite> CREATE TABLE FOO (name TEXT);
sqlite> INSERT INTO FOO VALUES('joe smith');
sqlite> SELECT * FROM FOO WHERE name = 'joe smith';
joe smith
If this is a one-off search, you might be better off trying the LIKE
operator to find the match:
sqlite> SELECT * FROM FOO WHERE name LIKE '%smith%';
joe smith
There's nothing wrong with that query.
If it's not returning results, it's because you've got a problem with your data. Are you storing as 'char' or 'varchar'? If it's 'char', then you'll have extra padding characters in there to watch for.
精彩评论