问题
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