Rob*_*t W 2 t-sql sql-server getdate
我有一个场景,我在事务中循环结果集,我需要通过结果集在每个迭代中插入一个唯一的日期时间值 - 每次都会重新计算GetDate()或者只是第一次计算它然后通过循环每次迭代都是一样的?
我的伪代码如下:
BEGIN TRANSACTION
GO
DECLARE @ID INT
DECLARE @table TABLE (/* Columns */)
WHILE (SELECT COUNT(*) FROM @table WHERE PROCESSED = 0) > 0
BEGIN
SELECT TOP 1 @ID = ID FROM @table WHERE PROCESSED = 0
-- INSERT GetDate() into child table at this point.
-- Will GetDate() be re-evaluated each time?
UPDATE @table SET PROCESSED = 1 WHERE ID = @ID
END
END TRANSACTION
GO
Run Code Online (Sandbox Code Playgroud)
提前致谢!
| 归档时间: |
|
| 查看次数: |
844 次 |
| 最近记录: |