
Signature
RelevantNoise.com - dedicated to mining blogs for business intelligence.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
Hi,
I donot want to use Multiple IF blocks as my IF criterias are huge...i want
to use some thing like
SELECT [ID] ,[Source] ,[Description],name
FROM [Search]
WHERE Source = CASE WHEN @allowSearchALL = 1 THEN Source ELSE 'mail' END
> You need an if statement
>
[quoted text clipped - 58 lines]
> >
> > Thanks in advance
Daniel Crichton - 23 Oct 2007 09:11 GMT
Vijay wrote on Tue, 23 Oct 2007 00:34:09 -0700:
> Hi,
> I donot want to use Multiple IF blocks as my IF criterias are huge...i
> want to use some thing like
> SELECT [ID] ,[Source] ,[Description],name
> FROM [Search]
> WHERE Source = CASE WHEN @allowSearchALL = 1 THEN Source ELSE 'mail'
> END
You can't - Hilary was suggesting the only viable alternative, other than
creating dynamic SQL.

Signature
Dan
Simon Sabin - 24 Oct 2007 20:38 GMT
Hello Vijay,
Daniel is correct. You don't have that option.
You best solution from a performance perspective is to use dyanmic SQL and
only add the criteria you need and then execute that. Make sure you use sp_executesql
and parameterise your query.
i.e.
declare @sql nvarchar(max)
declare @where nvarcha(max)
set @sql = 'SELECT [ID] ,[Source] ,[Description],name FROM [Search]'
if @allowSearch <> 1
set @where = 'contains (*,''mail'')'
set @sql = @sql + ' WHERE ' + @where
exec sp_executesql @sql
Simon Sabin
SQL Server MVP
http://sqlblogcasts.com/blogs/simons
> Hi,
>
[quoted text clipped - 73 lines]
>>>
>>> Thanks in advance
Vijay - 29 Oct 2007 15:19 GMT
Hi Simon Sabin,
Thanks for you reply.
How about this implementation...
SELECT [ID] ,[Source] ,[Description], name
FROM [Search]
WHERE (@allowSearchALL = 1) OR CONTAINS( Source , 'mail')
Pls suggest if this option is fine? will there be any performance hit ..if i
use the above query??
Thanks
Vijay
> Hello Vijay,
>
[quoted text clipped - 97 lines]
> >>>
> >>> Thanks in advance