用于搜索“关键字"的表字段的 T-SQL 查询

T-SQL query to search table-field for quot;Keywordsquot;(用于搜索“关键字的表字段的 T-SQL 查询)
本文介绍了用于搜索“关键字"的表字段的 T-SQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的网站上创建一个搜索文本框,而不是在提交时将字符串关键字"传递到我的网格中并提取该关键字的所有匹配记录.

I'm trying to create a search text-box on my website than when submitted will pass the 'string-keyword' into my grid and pull all matching records for that keyword.

我必须使用 where 语句设置我的网格,该语句将侦听"表单通过查询字符串传入的参数.

I'm having to setup my grid with a where statement that will "listen" for parameters passed in by the form via query-string.

我不知道如何解决这个问题.任何见解、提示、示例表示赞赏.

I'm not sure how to approach this. Any insight, tips, examples appreciated.

更新-------这是我的网格用于填充记录的查询.除了城市/地区/国家之外,我还尝试合并一个关键字搜索,它只会查看 BND_Listing 表中的公司"字段.

UPDATE------- This is the query my grid is using to populate records. In addition to City/Region/Country I'm trying to incorporate a keyword Search that would only look at my 'Company' Field inside the BND_Listing table.

select * FROM BND_listing right join BND_ListingCategories
on BND_Listing.CatID=BND_ListingCategories.CatID
where 
 (CategoryName = '[querystring:filter-Category]' or '[querystring:filter-     Category]'='All')
 and
 (City = '[querystring:filter-City]' or '[querystring:filter-City]'='All')
and
(Region= '[querystring:filter-State]' or '[querystring:filter-State]'='All')
and
(Country= '[querystring:filter-Country]' or '[querystring:filter-    Country]'='All')
and
isnull(Company,'') <> ''
ORDER by Company ASC

推荐答案

我不知道你说的监听"参数是什么意思,但因为你只有 TSQL 标记,匹配部分在 SQL Server 中是这样实现的:

I don't know what you mean by "listen" for parameters, but since you only have TSQL tagged, the matching part in SQL Server is achieved like so:

DECLARE @param VARCHAR(256)   --or what ever size you need
SET @param = 'some text'

SELECT SomeColumns
FROM SomeTable
WHERE aColumn LIKE '%' + @param + '%'

或者在 VB 中使用 SqlCommand 你可以查看:https://stackoverflow.com/a/251311/6167855

Or using SqlCommand in VB you can check out: https://stackoverflow.com/a/251311/6167855

这篇关于用于搜索“关键字"的表字段的 T-SQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)