子查询返回的值超过1。 (在while循环中插入)

时间:2016-09-13 07:37:18

标签: sql sql-server sql-server-2012 sql-server-2014 sql-server-2016

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

尝试插入以进行测试但与子查询一起堆叠在第9行返回了多于1个值的错误。

有什么想法吗? 此致

1 个答案:

答案 0 :(得分:2)

由于SQL中似乎没有任何子查询,请检查[watersave]表中是否有任何触发器。

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