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
 SQL Server Development (2000)
 trim

Author  Topic 

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2005-06-21 : 11:07:37
This is what I have at the moment
... where
Firstname like '%' + @name + '%'

If I pass the name 'best' the surname 'best' is returned
If I enter ' best ' nothing is returned whereas 'best' should still return.
Please note that I am using the charindex(' ', @name) to find out if there is a firstname and the lastname i.e. 'john brown'
Thanks

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-06-21 : 11:11:35
Firstname like '%' + rtrim(ltrim(@name )) + '%'

Go with the flow & have fun! Else fight the flow
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-06-21 : 11:11:38
I think It will return

declare @t table (name varchar(20))
insert into @t values('best')
insert into @t values('best ')
declare @s varchar(10)
set @s='best '
Select * from @t where name like '%'+@s+'%'


Madhivanan

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

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2005-06-21 : 11:14:05
quote:
Originally posted by spirit1

Firstname like '%' + rtrim(ltrim(@name )) + '%'

Go with the flow & have fun! Else fight the flow


Hi,
The initial post has been slightly changed. Please read the post again. Thanks
Go to Top of Page

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2005-06-21 : 11:16:48
Problem solved.
Wat I was missing was:
if (charindex(' ', ltrim(rtrim(@Name)))) > 0

Thank you all
Go to Top of Page
   

- Advertisement -