Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Like search with dash

Author  Topic 

purell
Starting Member

17 Posts

Posted - 2010-03-06 : 02:02:19
set @code=938-99123

Currently I have "select name from table1 where code like '%' + @code + '%'

But it won't work when I search for:
"9__-____3" or if I want to do exact search "___-__123" (only ending in 123).

How can I do this?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-06 : 02:15:13
if you want ones ending with 123 use

select name from table1 where code like '%' + @code
then pass @code as 123

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-08 : 02:13:10
quote:
Originally posted by purell

set @code=938-99123

Currently I have "select name from table1 where code like '%' + @code + '%'

But it won't work when I search for:
"9__-____3" or if I want to do exact search "___-__123" (only ending in 123).

How can I do this?


What do you mean by "It wont work?"
Did you get error or wront result?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -