You are here: Re: Creating WHERE clauses based on IF (or CASE) STATEMENTS Transact-SQL « MsSQL Server « IT news, forums, messages
Re: Creating WHERE clauses based on IF (or CASE) STATEMENTS Transact-SQL

Posted by ZeldorBlat on 11/17/05 04:53

>How about this:
>
>if @myparam = '' or @myparam is null
> @myparam = '%'
>else
> @myparam = '%' + @myparam + '%'
>
>select ...
>from mytable
>where MyField like @myparam

Actually, now that I've thought about it more, it would be silly (and
wasteful) to pattern match to everything. This might be better:

select ...
from mytable
where (@myparam = '' or @myparam is null
or charindex(@myparam,[MyField]) > 0))

 

Navigation:

[Reply to this 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

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