All Type Coding

Search Here

Conversion Decimal to Octal in Sql server.

Declare @num int=10,@rm varchar(50),
@temp varchar(50)='',@c varchar(100),@hold int
set @hold=@num;
if(@num=0)
set @temp=@num
print @temp
while(@num>0)

begin 
set @rm=@num%8;
set @num=@num/8;
set @temp=CAST(@rm as varchar)+CAST(@temp as varchar)
end
select CAST(@hold as varchar)'Decimal',@temp'Octal'

See the slide below with output.



No comments :

Post a Comment