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 2000 Forums
 Transact-SQL (2000)
 help with case statement

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2006-05-22 : 13:12:41
what's wrong with the code below?

SET @Lower = 1 -- The lowest random number
SET @Upper = 7 -- The highest random number
SELECT @Random = Round(((@Upper - @Lower -1) * Rand() + @Lower), 0)

CASE @Random
WHEN 1 THEN select @cvalue=100
WHEN 2 THEN select @cvalue=200
WHEN 3 THEN select @cvalue=300
WHEN 4 THEN select @cvalue=400
WHEN 5 THEN select @cvalue=500
WHEN 6 THEN select @cvalue=1000
WHEN 7 THEN select @cvalue=1500
END

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-05-22 : 13:14:13
SET @Lower = 1 -- The lowest random number
SET @Upper = 7 -- The highest random number
SELECT @Random = Round(((@Upper - @Lower -1) * Rand() + @Lower), 0)

select @cvalue =
CASE @Random
WHEN 1 THEN 100
WHEN 2 THEN 200
WHEN 3 THEN 300
WHEN 4 THEN 400
WHEN 5 THEN 500
WHEN 6 THEN 1000
WHEN 7 THEN 1500
END
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2006-05-22 : 13:21:06
thanks :)
Go to Top of Page
   

- Advertisement -