Subquery returned more than 1 value. (Insert within a while loop)

♀尐吖头ヾ 提交于 2019-12-12 02:19:13

问题


DECLARE @int int
DECLARE @saveamount int
DECLARE @savedate datetime
SET @int=1
SET @saveamount=400
SET @savedate= '20160101 13:00:00.00'
WHILE @int<=357
BEGIN
INSERT INTO watersave (reservoirid, amount, savedate)
             VALUES   (1,@saveamount,@savedate)


SET @int=@int+1
SET @saveamount=@saveamount+(SELECT ROUND((6 - 12 * RAND()), 0))
SET @savedate=@savedate+1
END

Trying to insert for test purposes but stacked with the subquery returned more than 1 value error on line 9.

Any idea? Regards


回答1:


Since there does not appear to be any sub-queries in your SQL, check to see if there are any triggers on the [watersave] table.

reference: SQL Server Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >=



来源:https://stackoverflow.com/questions/39464573/subquery-returned-more-than-1-value-insert-within-a-while-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!