user234194
user234194

Reputation: 1723

sql query with space in the value

How do I write where clause 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.

Upvotes: 2

Views: 27134

Answers (3)

Jerod Venema
Jerod Venema

Reputation: 44632

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.

Upvotes: 0

Mark Rushakoff
Mark Rushakoff

Reputation: 258238

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

Upvotes: 1

akf
akf

Reputation: 39485

That should work. The space within the quotes is valid. Perhaps there are spaces after the lastname, or the casing of lastname is incorrect.

Upvotes: 2

Related Questions