0
我運行以下查詢:子查詢返回的值超過1。當子查詢被用作表達
「子查詢返回超過1個值。這是:
從表
但是得到錯誤搜索特定圖案當子查詢如下=,!=,不允許<,< =,>,> =,或當子查詢用作表達「
DECLARE @SearchStr nvarchar(100)
SET @SearchStr = ''
--drop table #Results
CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))
SET NOCOUNT ON
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 = 'RAP1'
WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
BEGIN
SET @ColumnName =
(
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = PARSENAME(@TableName, 1)
AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar', 'int', 'decimal')
)
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
DROP TABLE #Results
什麼錯誤?如何獲得結果?請幫忙。
感謝。然而,它並沒有返回具有我正在搜索的特定字符串的所有列(在我的@SearchStr中) – AskMe
@TryingBest那麼,我只解決了腳本中運行腳本時遇到問題的部分。對於你在這裏提到的這個問題,我認爲你需要'''''''LIKE'的符號。 –
我有我喜歡的%符號。這裏:SET @ SearchStr2 = QUOTENAME('%'+ SearchStr +'%','''')我還在做錯什麼? – AskMe