Thread View: bit.databases.mssql-l
3 messages
3 total messages
Started by exist_world_beyond_yours
Mon, 24 Feb 2003 18:34
sql search keyword
Author: exist_world_beyond_yours
Date: Mon, 24 Feb 2003 18:34
Date: Mon, 24 Feb 2003 18:34
16 lines
1605 bytes
1605 bytes
Hello, I'm trying to search for particular word inside VARCHAR (not
entire phrase) but
WHERE
CIRCUIT.TABLE.NAME LIKE :keyword
only work for the entire phrase. Ex. " i go to java class" , search key
want to be consider match "java"
How do I code it in java?
ResultSet results = statement.executeQuery("SELECT * FROM CIRCUIT.TABLE
WHERE CIRCUIT.TABLE.NAME LIKE *"+keywordz+"*"); /* doesn't work */
Thank you for reviewing
Re: sql search keyword
Author: Brad McFarlane
Date: Mon, 24 Feb 2003 18:35
Date: Mon, 24 Feb 2003 18:35
27 lines
2024 bytes
2024 bytes
exist_world_beyond_yours wrote:
>
> Hello, I'm trying to search for particular word inside VARCHAR (not
> entire phrase) but
>
> WHERE
> CIRCUIT.TABLE.NAME LIKE :keyword
>
> only work for the entire phrase. Ex. " i go to java class" , search key
> want to be consider match "java"
>
> How do I code it in java?
>
> ResultSet results = statement.executeQuery("SELECT * FROM CIRCUIT.TABLE
> WHERE CIRCUIT.TABLE.NAME LIKE *"+keywordz+"*"); /* doesn't work */
>
> Thank you for reviewing
IIRC, the SQL wildcard character is "%" not "*", so I'd write the query
as:
"SELECT * FROM CIRCUIT.TABLE WHERE CIRCUIT.TABLE.NAME LIKE '%" +
keywordz + "%'" (and note that the whole pattern is enclosed in single
quotes).
Hope this helps/works,
Brad
Re: sql search keyword
Author: Ingo Pakleppa
Date: Tue, 25 Feb 2003 09:39
Date: Tue, 25 Feb 2003 09:39
31 lines
2322 bytes
2322 bytes
On Mon, 24 Feb 2003 13:35:52 +0000, Brad McFarlane wrote:
> exist_world_beyond_yours wrote:
>>
>> Hello, I'm trying to search for particular word inside VARCHAR (not
>> entire phrase) but
>>
>> WHERE
>> CIRCUIT.TABLE.NAME LIKE :keyword
>>
>> only work for the entire phrase. Ex. " i go to java class" , search
>> key want to be consider match "java"
>>
>> How do I code it in java?
>>
>> ResultSet results = statement.executeQuery("SELECT * FROM
>> CIRCUIT.TABLE
>> WHERE CIRCUIT.TABLE.NAME LIKE *"+keywordz+"*"); /* doesn't work */
>>
>> Thank you for reviewing
>
> IIRC, the SQL wildcard character is "%" not "*", so I'd write the query
> as:
>
> "SELECT * FROM CIRCUIT.TABLE WHERE CIRCUIT.TABLE.NAME LIKE '%" +
> keywordz + "%'" (and note that the whole pattern is enclosed in single
> quotes).
Actually, I would use a prepared statement. Otherwise, you will have a lot
of problems if keywordz happens to contain a single quote (there are other
ways around that, but prepared statements are generally best).
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads