Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
shapper
Constraint Violating Yak Guru
450 Posts |
Posted - 2008-02-24 : 21:00:21
|
| Hello,I am creating some dummy data in a table using the following Numbers Table:declare @Numbers table( n int identity(1,1) not null primary key clustered) while coalesce(scope_identity(), 0) <= 4begin insert @Numbers default valuesendAnd for inserting data in a table I am doing something like:insert into dbo.Categories (CategoryID, [Name])select newid(), 'Category ' + right('000' + convert(varchar(3), n + 1), 3)from @NumbersHowever I need to insert also a few random values and dates. This is where I am having the problem. I get always the same values. What I need and I am using is:1. A random date inside the range of -30 to +30 days of current date DATEADD(day, Round(((@UpperDay - @LowerDay - 1) * Rand() + @LowerDay), 1), getdate())2. A random date inside the range of -60 to -30 days of current date DATEADD(day, Round(((@LowerDay -1) * Rand() + @LowerDay), 1), getdate())3. A random date inside the range of +30 to +60 days of current date DATEADD(day, Round(((@UpperDay - 1) * Rand()), 1), getdate())4. A random date inside the range of -40 years to 0 years of the current date DATEADD(year, Round(((@LowerYear -1) * Rand() + @LowerYear), 1), getdate())5. A random float with 1 decimal between 0 and 4 Round(((@UpperRating - @LowerRating - 1) * Rand() + @LowerRating), 1)6. A random int number between 0 and 5 Round(((@UpperWeight - @LowerWeight -1) * Rand() + @LowerWeight), 0)7. A random bit convert(int, 2*rand())What am I doing wrong?Thanks,Miguel |
|
|
nathans
Aged Yak Warrior
938 Posts |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
|
|
shapper
Constraint Violating Yak Guru
450 Posts |
|
|
|
|
|
|
|