Hola a todos,
esto no es para mí, pero un amigo necesita generar una cadena
aleatoria para un programa. Definió una función así:
Create Function GenID_Unico (@Fecha Datetime)
Returns Varchar(20)
As
Begin
Declare @RandomNumber as int
SELECT @RandomNumber = rand()
Return (Select Left('123' + '000',3) +
Right('0000' + Cast(Datepart(yyyy,GetDate()) As
Varchar(4)),4) +
Right('00' + Cast(Datepart(mm,GetDate()) As
Varchar(2)),2) +
Right('00' + Cast(Datepart(dd,GetDate()) As
Varchar(2)),2) +
Right('00' + Cast(Datepart(hh,GetDate()) As
Varchar(2)),2) +
Right('00' + Cast(Datepart(mi,GetDate()) As
Varchar(2)),2) +
Right('00' + Cast(Datepart(ss,GetDate()) As
Varchar(2)),2) +
Substring(Cast(@RandomNumber As Varchar(10)),3,3))
End
Pero da un error porque no permite usar rand() dentro de la función.
Hay alguna forma de solucionar esto?
Muchas gracias.
Nota: yo remplacé dentro de la función el parámetro recibido por
getDate(), por eso no figura dentro.
Mauricio
Copenhague, Dinamarca
Leer las respuestas