fjtello / SQL-C-sharp

Common programming and coding tips and howtos
0 stars 0 forks source link

SQL hints [bitwise] #27

Open fjtello opened 7 years ago

fjtello commented 7 years ago

declare @t as table ( id int identity(1,1), valor int );

declare @inicio as int; set @inicio = 0; declare @final as int; set @final = 32;

declare @contador as int; set @contador = @inicio;

while(@contador < @final) begin insert into @t (valor) values (@contador); set @contador = @contador + 1; end

select valor, case (1 & valor) when 1 then '2^0' else '' end [2^0], case (2 & valor) when 2 then '2^1' else '' end [2^1], case (4 & valor) when 4 then '2^2' else '' end [2^2], case (8 & valor) when 8 then '2^3' else '' end [2^3], case (16 & valor) when 16 then '2^4' else '' end [2^4], case (32 & valor) when 32 then '2^5' else '' end [2^5] from @t order by id