Sunday, October 15, 2017

Like query ignore spacing in SQL

If your are searching in like query and string contain spaces then it will not search as you know space is also a character
for example in my table my fullname field is [B]Arvind  Kumar  as user is searching with arvind kumar it will not fetch out the records, so what you have to do  use replace function



declare @FullName  as Varchar(MAX)=''
set @FullName='arvind kumar'
set @FullName=REPLACE('%'+@FullName+'%', ' ', '')

select * from Customer WHERE REPLACE(FullName, ' ', '') like   COALESCE('%'+@FullName+'%',customer.FullName)

No comments:

Post a Comment