Generating a HEX Number | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Generating a HEX Number

I wanted to know how to generate a sequential HEX number of 7 digits, followed by a random HEX number of 3 digits For Example some thing like this 113A5193F5
declare @max int, @rand int, @num bigint, @startnum bigint
set @startnum = cast(0x113A519000 as bigint)
set @max = cast(0xfff as int)
declare @t table (id bigint)
declare @i int
set @i = 0 while (@i < 1000)
set @rand = cast(rand() * @max as int)
insert into @t select @rand + @startnum
set @startnum = @startnum + 1
set @i = @i + 1
end select id, cast(id as varbinary(10)) from @t
EDIT: added [ code ] tags to fix formatting. SqlSpec: a fast and comprehensive data dictionary generator for
SQL Server 2000/2005, Analysis Server 2005, Access 97/2000/XP/2003

You can also take three characters from NEWID() Madhivanan Failing to plan is Planning to fail