我对光标很新。但我试图在游标中运行自定义函数。该功能有效。但是如果光标被运行,则没有显示数据。我该如何解决?您的意见将不胜感激。感谢。
DECLARE @fName varchar(50), @lName varchar(50)
DECLARE cursorName CURSOR
LOCAL SCROLL STATIC
FOR
SELECT fName, lName FROM TABLEA
OPEN cursorName
FETCH NEXT FROM cursorName
INTO @fName, @lName
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT * FROM dbo.data (@lName, @fName)
FETCH NEXT FROM cursorName
INTO @fName, @lName
END
CLOSE cursorName
DEALLOCATE cursorName
答案 0 :(得分:2)
您可以使用cross apply
完全摆脱光标select
x.*
from
tablea a
cross apply
dbo.data(a.fName, a.lName) x