mercredi 5 février 2020

using NEWID() inside a function - as variable - but getting the same value every time. sql server

I'm using NEWID() inside a function. this is my function:

CREATE FUNCTION dbo.myFunc (@newid NVARCHAR(50))
RETURNS int

AS BEGIN
    declare @rndValue int
    set @rndValue = (SELECT top 1 * FROM #temp ORDER BY lower(@newid))
    RETURN @rndValue 
END

i have #temp with values: '1','2','3' i want to random from this table using this function. i called this function like this:

dbo.myFunc (NEWID())

but i'm getting every time the same value ('1')

where is my error?




Aucun commentaire:

Enregistrer un commentaire