由于权限较少,我不能将此作为评论,但如果您要搜索由表保存的值(可以是任何列) - 您可以查看此SO 帖子
使用同一篇文章中的代码 -
DECLARE @Results TABLE(ColumnName nvarchar(370), ColumnValue nvarchar(3630))
DECLARE @SearchStr nvarchar(100)
DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
SET @TableName = 'no'
SET @SearchStr2 = QUOTENAME('%' + 'no' + '%','''')
SET @ColumnName = ''
SET @TableName = '[test].[dbo].[subscription]'
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
SELECT ColumnName, ColumnValue FROM @Results