gpt4 book ai didi

sql - 对一系列元素执行过程(执行 theProc(从表中选择 id))

转载 作者:行者123 更新时间:2023-12-01 11:59:44 25 4
gpt4 key购买 nike

我需要为这个选择查询返回的每个元素执行过程 deleteQuestion:

select id from questions where Stuff = @Stuff

execute deleteQuestion id

类似于:
执行 deleteQuestion each(select id fom questions where Stuff = @Stuff)

有人知道吗?

最佳答案

使用 cursor :

DECLARE @Id INT
DECLARE your_cursor CURSOR FOR
SELECT id from questions where Stuff = @Stuff

OPEN your_cursor

FETCH NEXT FROM your_cursor
INTO @Id

WHILE @@FETCH_STATUS = 0
BEGIN

execute deleteQuestion @Id

FETCH NEXT FROM your_cursor
INTO @Id

END
CLOSE your_cursor
DEALLOCATE your_cursor

关于sql - 对一系列元素执行过程(执行 theProc(从表中选择 id)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2864018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com