Groups | Blog | Home
all groups > sql server full text search > april 2004 >

sql server full text search : Optional CONTAINS


John Kane
4/23/2004 9:47:46 AM
Matias,
I'm not sure if a CASE construct can be used is such as you describe below,
but you might want to instead consider an IF... THEN ...ELSE construct, for
example:

-- FTS and IF/THEN/ELSE construct
Declare @searchstring varchar(255)
if(@param1 = '')
SELECT * FROM address
else
SELECT * FROM address WHERE CONTAINS(name, @searchstring)

Regards,
John



[quoted text, click to view]

Matias Woloski
4/23/2004 12:13:19 PM
Hi guys,

I'm using FTS on sql server 2000

I would like to write a stored proc that accepts conditional CONTAINS. This
means that if @param1 was provided I want to apply CONTAINS with certain
column if not apply it to the other column

WHERE

CASE

WHEN @param2 IS NULL THEN CONTAINS(param1, @param1)

ELSE CONTAINS(param2, @param2)

END

Something like that I would like to do... But something that works ;)

Thanks,

Matias


Matias Woloski
4/23/2004 2:19:10 PM
Thanks.

I know CASE cannot be used there... The problem is that I want to keep the
query small... there are lot of alternatives in the query, I don't want to
copy paste the query all over the place...
You know this is easy using COALESCE, but doesn't work with CONTAINS
WHERE
someField = COALESCE( @someField, someField)

This is an optional filter for the query... the problem is that by using
CONTAINS, I cannot use COALESCE in this way...

Matias

[quoted text, click to view]

John Kane
4/25/2004 1:40:17 PM
Matias,
Are you still looking for solutions other than the IF... THEN ELSE
construct?
Have you considered using dynamic SQL and then executing the concated
string?

Regards,
John




[quoted text, click to view]

AddThis Social Bookmark Button