Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.
declare @TempAv int
declare @TempVar int
declare @temp int
declare @rain int
While @count <= (Select top 1 [num] from Map order by [num] desc)
BEGIN
--Get Variables for this area
set @TempAv = (Select [TempAv] from [map] where [num]=@count)
set @TempVar = (Select [TempVar] from [map] where [num]=@count)
--Set Temperature
If @Season = '0'
set @temp = @TempAv + convert(int, 0 + @TempVar * RAND(CHECKSUM(NEWID()))) - (@TempVar / 2)
Else if @Season = '1'
set @temp = @TempAv + convert(int, 0 + @TempVar * RAND(CHECKSUM(NEWID()))) + (@TempVar / 2)
Else if @Season = '2'
set @temp = @TempAv + convert(int, 0 + @TempVar * RAND(CHECKSUM(NEWID()))) - (@TempVar / 2)
Else if @Season = '3'
set @temp = @TempAv - convert(int, 0 + @TempVar * RAND(CHECKSUM(NEWID()))) - (@TempVar / 2)
update Map
Set [TempNow] = @temp where [num] = @count
END
update Map
Set [TempNow] = TempAv
+ CASE @Season
WHEN '3' THEN -1
ELSE 1
END * CAST(0 + @TempVar * RAND(CHECKSUM(NEWID())) AS INT)
- CASE @Season
WHEN '1' THEN -1
ELSE 1
END * (TempVar / 2);
update [Map]
set [TempNow] = case @Season when '0' then TempAv + convert(int, 0 + TempVar * RAND(CHECKSUM(NEWID()))) - (TempVar / 2)
when '1' then TempAv + convert(int, 0 + TempVar * RAND(CHECKSUM(NEWID()))) + ( TempVar / 2)
when '2' then TempAv + convert(int, 0 + TempVar * RAND(CHECKSUM(NEWID()))) - ( TempVar / 2)
when '3' then TempAv - convert(int, 0 + TempVar * RAND(CHECKSUM(NEWID()))) - ( TempVar / 2)
else 0
end
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
+Only variation I saw in the formula was if season was '3', you subtract the latter portion of formula versus add.
+TempAv and TempVar appear to come from same row, so should not need to store in variables first.
Open in new window