You are here: Re: Need SELECT ... LIKE help, please « MsSQL Server « IT news, forums, messages
Re: Need SELECT ... LIKE help, please

Posted by manning_news on 07/05/07 21:18

On Jul 5, 4:01 pm, Jason Lepack <jlep...@gmail.com> wrote:
> SELECT
> FirstName,
> LastName,
> BusinessName,
> MailingAddress1
> FROM
> tblAddresses
> WHERE
> FirstName LIKE '%' + ISNULL(@FirstName, '') + '%'
> AND
> (
> LastName LIKE '%' + ISNULL(@LastName, '') + '%'
> OR LastName is null
> )
>
> On Jul 5, 4:56 pm, manning_n...@hotmail.com wrote:
>
>
>
> > I've got the following SELECT statement in a stored procedure:
>
> > SELECT FirstName, LastName, BusinessName, MailingAddress1
> > FROM tblAddresses
> > WHERE FirstName LIKE '%' + ISNULL(@FirstName, '') + '%' AND
> > LastName LIKE '%' + ISNULL(@LastName, '') + '%'
>
> > If I input "tom" for @FirstName then it returns rows with "tom"
> > somewhere in the first name but that row must have a last name too in
> > order to be returned. How do I change this to return both types of
> > rows: one with "tom" as a firstname and with a lastname and one with
> > "tom" as first name but no last name?
>
> > Thanks for any help or advice.- Hide quoted text -
>
> - Show quoted text -

OK, thank you! I was missing the "OR LastName is null)" The proc
works great now.

 

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

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