Home All Groups Group Topic Archive Search About

using like keyword with variable

Author
25 Nov 2005 5:07 AM
Manish Sukhija
Hi All,
         i have a case in which i want to match records in table which
should be start with a word, which i'm storing in a varchar varaible.
                                               How could i do this?

Author
25 Nov 2005 5:17 AM
David Gugick
Manish Sukhija wrote:
> Hi All,
>         i have a case in which i want to match records in table which
> should be start with a word, which i'm storing in a varchar varaible.
>                                               How could i do this?

Select MyCol From dbo.MyTable Where MyCol2 Like 'MY_PREFIX%'

An index on MyCol2 will probably help.


--
David Gugick
Quest Software
www.imceda.com
www.quest.com
Author
25 Nov 2005 5:20 AM
Uri Dimant
Hi

create table #test
(
col varchar(100) not null
)

insert into #test values ('Bill Clinton')
insert into #test values ('Joe Celco')
insert into #test values ('John Smith')
insert into #test values ('Ron Garden')

declare @var varchar(50)

set @var='J'
select col from #test where col like @var+'%'




Show quote
"Manish Sukhija" <ManishSukh***@discussions.microsoft.com> wrote in message
news:01232210-9D70-43FB-9363-86EAFF0EEC5E@microsoft.com...
> Hi All,
>         i have a case in which i want to match records in table which
> should be start with a word, which i'm storing in a varchar varaible.
>                                               How could i do this?
Author
25 Nov 2005 5:46 AM
Manish Sukhija
thanks Uri, it was great.

Show quote
"Manish Sukhija" wrote:

> Hi All,
>          i have a case in which i want to match records in table which
> should be start with a word, which i'm storing in a varchar varaible.
>                                                How could i do this?

AddThis Social Bookmark Button