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 |
|
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 intselect @outval = cast(@xval * (@inrand + 1) as int)return @outvalEND 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 5Syntax error converting the varchar value '0.0329991' to a column of data type int.help me out from this problem... Thanks in advanceanwer |
|
|
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 floatselect @outval = cast(@xval * (@inrand + 1) as float)return @outvalEND Declare @a as floatset @a = RAND() select cast(sqldb.random(@a,10) as int) |
 |
|
|
|
|
|