Reply to Creating WHERE clauses based on IF (or CASE) STATEMENTS Transact-SQL

Your name:

Reply:


Posted by Ryan on 11/17/05 04:36

I am trying to create a stored procedure whose where clause is
dependent on a parameter.

If the parameter @myparam is null or '' then I want the where clause to
be one thing, else I want it to be a completely different thing. I can
do it easily using iif but obviously that is not an option here...

Here is what I have:

Select @ FROM my table WHERE

IF @myparam = '' or @myparam is null
[MyField] = like '%'
ELSE
charindex(@myparam,[MyField]) > 0)

I have also tried variations of this and tried it using CASE. I keep
getting syntax errors. Do I have to write multiple SELECT statements
for every possibility. If I can get this working the query will
actually be a bit more complex, although it will follow this basic
structure...in other words, I'd rather not have to write multiple
queries when the only thing that is changing is the WHERE portion...

Thanks!
Ryan

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация