>I am constructing a document number. It has several codes such as '05' of r fiscal year, and 'AB' for type, etc. It also has a two character counter imbedded in it, and it is space constrained (i.e. I am not able to expand the counter to three digits.) There needs to be room for 200 + items in any given set of numbers. Hexadecimal would take care of this, but I am not able to convert back and forth from binary to char. Currently there is a manual method that uses a table of alpha counters (AA, AB, AC, ... ZZ).
>
>Does that help?
>
Here's the code that will convert between integer and base36 in both directions
DECLARE @i int, @cnt int, @Base36 char(36), @cnt36str char(2), @cntint int
SET @cnt = 255
SET @Base36 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
SET @cnt36str = SUBSTRING(@Base36, (@cnt / 36)+1,1) +
SUBSTRING(@Base36, (@cnt % 36)+1,1)
SELECT @cnt36str
SET @cntint = ( CHARINDEX(SUBSTRING(@cnt36str,1,1),@Base36) - 1) * 36 +
CHARINDEX(SUBSTRING(@cnt36str,2,1),@Base36) - 1
SELECT @cntint
--sb--