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 2000 Forums
 Transact-SQL (2000)
 how to search on bases of first three characters

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 Shahid
Software 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 Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-05 : 04:17:41
Where column like 'value%'

Madhivanan

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

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 characters

Kamran Shahid
Software Engineer(MCSD.Net)
www.netprosys.com
Go to Top of Page

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
Go to Top of Page

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 characters

Kamran Shahid
Software Engineer(MCSD.Net)
www.netprosys.com



Or

Post some sample data with expected result

Madhivanan

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

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 Yourtable
where 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
Go to Top of Page
   

- Advertisement -