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.
Author |
Topic |
kamii47
Constraint Violating Yak Guru
353 Posts |
Posted - 2007-10-05 : 03:27:52
|
I want te search my string on the bases of the first three or less charaters with like how can i do that ?Kamran ShahidSoftware Engineer(MCSD.Net)www.netprosys.com |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-10-05 : 03:58:10
|
88 posts!By now you should know how to properly post a question. How about giving some sample data and expected output?Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-05 : 04:17:41
|
Where column like 'value%'MadhivananFailing to plan is Planning to fail |
 |
|
kamii47
Constraint Violating Yak Guru
353 Posts |
Posted - 2007-10-05 : 05:05:16
|
only problem is the search should be on the bases of three or less.Currently i have to do substring in my C# code upto three characters and search but it is not valid when the string is less then three charactersKamran ShahidSoftware Engineer(MCSD.Net)www.netprosys.com |
 |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2007-10-05 : 05:14:48
|
LIKE will still work though. enter 1 character and it will match the first, enter 2 and it will match the first 2, etc...is that not what your looking for?Em |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-05 : 05:22:51
|
quote: Originally posted by kamii47 only problem is the search should be on the bases of three or less.Currently i have to do substring in my C# code upto three characters and search but it is not valid when the string is less then three charactersKamran ShahidSoftware Engineer(MCSD.Net)www.netprosys.com
OrPost some sample data with expected resultMadhivananFailing to plan is Planning to fail |
 |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2007-10-05 : 05:42:58
|
or did you actually want something like...declare @searchvalue varchar(3) set @searchvalue = 'abc'select *from Yourtablewhere yourfield like (case when len(yourfield) >= 3 then @searchvalue + '%'when len(yourfield) = 2 then substring(@searchvalue,1,2) + '%'when len(yourfield) = 1 then substring(@searchvalue ,1,1) + '%'else '' end)Em |
 |
|
|
|
|