query to search even when user skips in between text | Familiar Sight | | Join Date: Oct 2008
Posts: 128
| | |
i have a database as
table name school
field name location
eg in location column data
green school,tagore garden,chink road,jammu
i want to make search on location such that when user enter
green
green school, tagore
search words should come continous
problem
on skipping in between text
eg on entering
green school, jammu
record not show
search query is
select*from school where location like'%a%'
plz suggest me query to search even when user skips in between text
|  | Expert | | Join Date: Jun 2007
Posts: 1,925
| | | re: query to search even when user skips in between text
Use the PATINDEX() function.
-- CK
| | Familiar Sight | | Join Date: Oct 2008
Posts: 128
| | | re: query to search even when user skips in between text Quote:
Originally Posted by ck9663 Use the PATINDEX() function.
-- CK no patindex is also not working when user skips in between text
|  | Expert | | Join Date: Jun 2007
Posts: 1,925
| | | re: query to search even when user skips in between text
Tweak this code -
declare @str as varchar(100)
-
declare @str1 as varchar(50)
-
-
set @str = 'green school,tagore garden,chink road,jammu'
-
set @str1 = 'tagore garden,jammu'
-
set @str1 = '%' + replace(@str1,',','%') +'%'
-
select patindex(@str1, @str)
-
-
-
set @str = 'green school,tagore garden,chink road,jammu'
-
set @str1 = 'green school,jammu'
-
set @str1 = '%' + replace(@str1,',','%') +'%'
-
select patindex(@str1, @str)
-
-- CK
| | Familiar Sight | | Join Date: Oct 2008
Posts: 128
| | | re: query to search even when user skips in between text Quote:
Originally Posted by ck9663 Tweak this code -
declare @str as varchar(100)
-
declare @str1 as varchar(50)
-
-
set @str = 'green school,tagore garden,chink road,jammu'
-
set @str1 = 'tagore garden,jammu'
-
set @str1 = '%' + replace(@str1,',','%') +'%'
-
select patindex(@str1, @str)
-
-
-
set @str = 'green school,tagore garden,chink road,jammu'
-
set @str1 = 'green school,jammu'
-
set @str1 = '%' + replace(@str1,',','%') +'%'
-
select patindex(@str1, @str)
-
-- CK thank u so much for your guidance now its working
|  | Similar Microsoft SQL Server bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,439 network members.
|