I apologize if I seem unknowledgable. I have only been writing T-SQL for about 3 years now and most is self-taught. At my work we store Day of month values in bitmasks. eg. 1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx converts to 1, and 12345678910111213141516171819202122232425262728293031 converts to 2147483647. What I want/need to do is convert the int value into a varchar(64) containing numbers and 'x' characters. I have the following code from another post on here that kind of does something similar with some tweaking, but it provides the data backwards (right to left [as it should for binary] instead of left to right).
    declare @i int /* input */
    set @i = 42
    declare @result varchar(32) /* SQL Server int is 32 bits wide */
    set @result = ''
    while 1 = 1 begin
     select @result = convert(char(1), @i % 2) + @result,
           @i = convert(int, @i / 2)
     if @i = 0 break
    end
    select Replace(@result,'0','X')
It also does not provide all of the characters. All 31 characters must be backfilled.
I have also played with Rob Farley's Simple Recursive CTE for this.
 
     
    