gpt4 book ai didi

SQL 将变量设置为当前行中的值

转载 作者:行者123 更新时间:2023-12-05 05:27:42 25 4
gpt4 key购买 nike

我想做的是执行一个循环遍历表中的每一列,并将变量@agent 设置为该列的 agentID。

这是我目前的代码:

    Declare @index int = 1
Declare @agentCount = Max(rowID)
Declare @agentID int

While(@i =< @agentCount)
Begin
If(@index = rowID)
Begin
--Set @agentID (to current row's agentID)
Exec mergeagentLogRecords @agentID, @startDate, @endDate
End
Set @index = @index + 1
End

我希望我对自己的解释足够好 :P感谢您的关注!

最佳答案

您可能想做这样的事情,具体取决于您生成 rowID 的方式:

SELECT @agentID = agentID FROM agentTable WHERE @index = rowID;

然后继续您的快乐之路,无论您的逻辑需要做什么。

关于SQL 将变量设置为当前行中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17598001/

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