I'm trying to create the function in SQL Server. In this function I have generated the random number, but function not generated.
Create function [GetRandomNumber]
(
)
RETURNS bigint
as
Begin
Declare @randomNo int
set @randomNo = (select round(rand(checksum(newid()))*(10001)+50000,0) as [GetRandomNumber])
return @randomNo
End
this is generated in following error:
Invalid use of a side-effecting operator 'newid' within a function.
Msg 443, Level 16, State 1, Procedure GetRandomNumber, Line 8
Invalid use of a side-effecting operator 'rand' within a function.
CONVERT(INT, CRYPT_GEN_RANDOM(4))(orBIGINTand8, your return type and expression contradict each other).