Làm thế nào để có được kết quả trong WITH table AS
vào vòng lặp CURSOR
? Tôi đã từng hỏi về làm thế nào để có được kết quả đệ quy từ bàn của tôiLàm thế nào để sử dụng VỚI bảng AS kết quả trong vòng lặp con trỏ để chạy thủ tục được lưu trữ
How to read all records recursively and show by level depth TSQL
;with C as
(
definition ...
)
Tôi đã tạo ra vòng lặp CURSOR nơi tôi muốn chạy thủ tục lưu trữ cụ thể cho tất cả các kết quả trong table
declare @id int, @parent int
declare cur cursor local fast_forward
for
select id, parent from C
open cur
fetch next from cur into @id, @parent
while @@fetch_status = 0
begin
exec storedProcedure @[email protected], @[email protected]
fetch next from cur into @id, @parent
end
close cur
deallocate cur
Vấn đề là CURSOR không biết table
từ WITH AS.
Invalid object name 'C'.