[英]server side search functionality
need to implement server side Search functionality 需要实现服务器端搜索功能
My requirement is as follows: 我的要求如下:
The string inserted in the textbox has to checked in every column-data in the database. 插入文本框中的字符串必须检入数据库中的每个列数据。 if it matches or the string is contained by any of the column-data in the database that row is valid for displaying.
如果匹配或该字符串包含在数据库中的任何列数据中,则该行对于显示有效。 There is a pagination part too, that is also handled in the DB and the stored procedure has to send only an specified no of rows calculated based on the pageIndex , and rowCount passed to the stored Procedure, this calculation also is happening in the stored procedure only.
还有一个分页部分,它也在数据库中处理,并且存储过程只需要发送基于pageIndex计算的指定行数,并且将rowCount传递给存储过程,该计算也在存储过程中进行只要。
In the Stored procedure we are pulling the data from Different table using joins and pushing it to a temporary table, and finally the data from the temporary table is sent back. 在存储过程中,我们使用联接从Different表中提取数据并将其推入临时表中,最后将临时表中的数据发送回去。
Here my problem is I am not able to use the Contains() method for searching the pattern so what should be the approach to wards this functionality. 在这里,我的问题是我无法使用Contains()方法搜索模式,因此应采用什么方法来保护此功能。 so that this can be done efficiently??
这样才能有效地做到这一点?
thanks 谢谢
Check following query. 检查以下查询。 You need to replace test with the value you want to search.
您需要将test替换为要搜索的值。 This will give Column name and value of matching string.
这将给出列名和匹配字符串的值。 I hope this will help you to find your answer.
希望这可以帮助您找到答案。
Declare @SearchStr nvarchar(100)
set @SearchStr='test'
DECLARE @Results TABLE (ColumnName nvarchar(370), ColumnValue nvarchar(3630))
DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
SET @TableName = ''
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')
WHILE @TableName IS NOT NULL
BEGIN
SET @ColumnName = ''
SET @TableName =
(
SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
AND OBJECTPROPERTY(
OBJECT_ID(
QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
), 'IsMSShipped'
) = 0
)
WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
BEGIN
SET @ColumnName =
(
SELECT MIN(QUOTENAME(COLUMN_NAME))
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = PARSENAME(@TableName, 2)
AND TABLE_NAME = PARSENAME(@TableName, 1)
AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')
AND QUOTENAME(COLUMN_NAME) > @ColumnName
)
IF @ColumnName IS NOT NULL
BEGIN
INSERT INTO @Results
EXEC
(
'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630)
FROM ' + @TableName + ' (NOLOCK) ' +
' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
)
END
END
END
SELECT ColumnName, ColumnValue FROM @Results`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.