Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
TSQL - Globally unique string generator
declare @characterPool varchar(256) = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; declare @outputLength int = 32; declare @n int = 0; /* counter */ declare @numLoops int = ceiling(log(len(@characterPool)) / log(2) * @outputLength / 128) declare @e varbinary(128) = 0x; /* entropy */ while @n < @numLoops begin set @e += cast(newid() as binary(16)); set @n += 1; end declare @b int; /* byte */ declare @d int; /* dividend */ declare @out varchar(128) = ''; declare @outputBase int = len(@characterPool); declare @entropyBytes int = len(@e); declare @m int = 0; while @m < @outputLength begin set @b = 0; set @d = 0; set @n = 0; while @n < @entropyBytes /* big-endian */ begin set @b = (@b - @d * @outputBase) * 256 + cast(substring(@e, @n + 1, 1) as int); set @d = @b / @outputBase; set @e = cast(stuff(@e, @n + 1, 1, cast(@d as binary(1))) as varbinary(128)); set @n += 1; end set @out = substring(@characterPool, @b - @d * @outputBase + 1, 1) + @out; set @m += 1; end select @out as "UniqueString"
run
|
edit
|
history
|
help
0
03_A_Group_by_having
Greatest_N_Per_Group
Students
Comercio
Combined Where and having
Create Date list (variable dates) - SQL Server
Performance test - select vs while - Get all days between two dates.
newtable
Chris
sc