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
 SQL Server Development (2000)
 Where i am wrong using rand() function

Author  Topic 

mdanwerali
Starting Member

30 Posts

Posted - 2002-12-09 : 04:33:32
Hi all,

I am writing an user defined function and passing the rand() function as a parameter but i am getting an error.

Create FUNCTION random(@inrand varchar(100),@xval int) RETURNS int AS
BEGIN
Declare @outval as int

select @outval = cast(@xval * (@inrand + 1) as int)
return @outval
END

Without any errors this function executed successfully. but how to run this... is this the proper way of executing it?

select sqldb.random(rand(),10)

Even i have Declared a variable x and assigned rand() function to that variable but still i am getting the same problem.

The error is :

Server: Msg 245, Level 16, State 1, Procedure random, Line 5
Syntax error converting the varchar value '0.0329991' to a column of data type int.


help me out from this problem...

Thanks in advance

anwer

mdanwerali
Starting Member

30 Posts

Posted - 2002-12-09 : 04:46:47
Sorry for troubling you ppl, my problem is solved. before i am converting to int within the function now i am doing it in the calling statement.


alter FUNCTION random(@inrand float,@xval int) RETURNS float AS
BEGIN
Declare @outval as float

select @outval = cast(@xval * (@inrand + 1) as float)
return @outval
END

Declare @a as float
set @a = RAND()
select cast(sqldb.random(@a,10) as int)


Go to Top of Page
   

- Advertisement -