SQL Random number not working
Posted
by JMSA
on Stack Overflow
See other posts from Stack Overflow
or by JMSA
Published on 2009-06-24T14:21:18Z
Indexed on
2010/03/24
5:03 UTC
Read the original article
Hit count: 372
declare @fieldForceCounter as int
declare @SaleDate as dateTime
declare @RandomNoSeed as decimal
set @fieldForceCounter = 1
set @SaleDate = '1 Jan 2009'
set @RandomNoSeed = 0.0
WHILE @fieldForceCounter <= 3
BEGIN
while @SaleDate <= '1 Dec 2009'
begin
INSERT INTO MonthlySales(FFCode, SaleDate, SaleValue) VALUES(@fieldForceCounter, @SaleDate, RAND(@RandomNoSeed))
set @saleDate = @saleDate + 1
set @RandomNoSeed = Rand(@RandomNoSeed) + 1
end
set @SaleDate = '1 Jan 2009'
set @fieldForceCounter = @fieldForceCounter + 1
END
GO
This T-SQL command was supposed to insert random values in the 'SaleValue
'-column in the 'MonthlySales
'-table.
But it is inserting '1' every time .
What can be the problem?
© Stack Overflow or respective owner