我在数据库和表格中找到了要搜索的单词表
id Name Word
----------------------------------
1 word search c&a
2 word search Beton
3 word search Freiman
4 Anything Null
除此之外,我有Procedure SearchAllTable,这是搜索过程和搜索数据库中的单词。
DECLARE @id int
DECLARE @name varchar(100)
DECLARE @word varchar(100)
DECLARE cur CURSOR FOR SELECT Id, word FROM #Parameter WHERE Name = 'word search'
OPEN cur
FETCH NEXT FROM cur INTO @id,@word
WHILE @@FETCH_STATUS = 0 BEGIN
EXEC SearchAllTables @word
FETCH NEXT FROM cur INTO @id, @word
END
CLOSE cur
DEALLOCATE cur
我在multipule表中得到了结果的问题,我希望它们都能在一个表中列出而没有任何化身。
答案 0 :(得分:1)
答案 1 :(得分:0)
将结果收集到临时表或表变量中,并在光标外的单个选择中获取它。请试试吼叫。
DECLARE @id int
DECLARE @name varchar(100)
DECLARE @word varchar(100)
--Create Result table wrt your SP output
DECLARE @Result TABLE (NAME VARCHAR(16), DATEVAL DATETIME)
DECLARE cur CURSOR FOR SELECT Id, word FROM @Parameter WHERE Name = 'word search'
OPEN cur
FETCH NEXT FROM cur INTO @id,@word
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO @Result
EXEC SearchAllTables @word
FETCH NEXT FROM cur INTO @id, @word
END
CLOSE cur
DEALLOCATE cur
--Selecting result as a single unit
SELECT * FROM @Result