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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Random allocation

Author  Topic 

Rheinhardt
Yak Posting Veteran

66 Posts

Posted - 2011-03-10 : 07:20:05
Hi,

I am doing a scenario with Item master file but don't have the Item cost prices, but I know in what bracket the item cost is so I can asume ballpark figure for the purpose of this exercise...my problem: I want to allocate RANDOM item cost prices between a certain amount (exmple: >USD20 and <USD30) to the all Items, example:

ItemName,CostPrice
'Itema',USD21
'Itemb',USD20
'Itemc',USD29
'Itemd',USD30
'Iteme',USD23 etc

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-03-10 : 07:23:12
so basically you want to generate some random number ?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=69499&SearchTerms=F_RANDOM_INTEGER


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Rheinhardt
Yak Posting Veteran

66 Posts

Posted - 2011-03-10 : 07:27:31
yes, but specify the number between x and y.
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2011-03-10 : 08:01:15
[code]
--> Usage: SELECT dbo.randomnumber (20, 25, RAND())

create function randomnumber (@min bigint, @max bigint, @rand float)
returns bigint
as
begin
return CAST(((@Max + 1) - @Min) * @Rand + @Min AS bigint)
end
go[/code]

- Lumbago
My blog-> http://thefirstsql.com/2011/02/07/regular-expressions-advanced-string-matching-and-new-split-function-sql-server-2008-r2/
Go to Top of Page

Rheinhardt
Yak Posting Veteran

66 Posts

Posted - 2011-03-10 : 08:20:40
thanks
Go to Top of Page
   

- Advertisement -