如何编写查询以按城市,州,县之类的位置进行搜索 [英] how to write a query for search by location like city,state,county

查看:189
本文介绍了如何编写查询以按城市,州,县之类的位置进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个像搜索框一样的文本框.
如何编写对城市,州等搜索数据的查询

hi all,

i have one textbox like search box..
how to write a query for search data like city,state

TableA
------
Address1
Address2
City
State
Zip


表格中以上所有列均为全文索引.假设用户输入的是"123 Apple street FL 33647",而我在表中的记录为


All the above columns in the table are full text indexed. Let''s say if the user enters "123 Apple street FL 33647" and I have a record in the table as

 City = "Tampa", State = "FL". I would like the query to return this.am enter into the text in search box like Tampa,FL. but i did not get any records. my query like this 
CITY LIKE '%'+@SERCHTEXT OR CITY LIKE '%'+@SERCHTEXT+'%' OR CITY LIKE @SERCHTEXT+'%'  
OR
[STATE] LIKE '%'+@SERCHTEXT OR [STATE] LIKE '%'+@SERCHTEXT+'%' OR [STATE] LIKE @SERCHTEXT+'%'


当进入城市或州时,我只有正确的输出

你能让我知道我将如何做吗?

谢谢您.


when enter the city or state only i got the correct output

can you please let me know how I would do this.

thanking you

推荐答案

在SQL或String中使用like关键字.在C#中使用contain关键字,您也可以在此处使用lambda表达式或Linq查询.

谢谢,
Ambesha
use the like keyword in SQL or String.Contain keyword in C# also you can use the lambda expression or Linq query here.

Thanks,
Ambesha


http ://msdn.microsoft.com/en-us/library/ms142488(v = sql.105).aspx [
http://msdn.microsoft.com/en-us/library/ms142488(v=sql.105).aspx[^]

or you can try like this :-

Select * from TableA where city like @Str1 or state like @Str1 or country like @str3


您需要非常编写此代码的同时又聪明又意识到

算法会像这样
1.获取地址字符串
2.用空格将字符串滑动
3.创建查询
4.将滑动的字符串成员传递到查询的where子句.

我相信您的查询在where子句中包含AND条件.用户未提供状态"TEMPA",因此它将失败.我会建议您根据用户提供的内容创建动态查询字符串.
You need to very smart and aware while writing code for this

algo will be like this
1. Get the address string
2. slipt the string by whitespace
3. create a query
4. pass the slipted string members to where clause of your query .

I believe your query contains AND condition in the where clause. the state ''TEMPA'' is not provided by the user hence it will fail. i will suggest you to create dynamic query string depending upon what user had provided.


这篇关于如何编写查询以按城市,州,县之类的位置进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆