Conversion between SQL binaries

Source: Internet
Author: User

-----Binary Conversion Decimal-----------------Select SUM (data1) from (Select substring (' 11011 ', number, 1) *power (2,len (' 11011 ')- Number) Data1 from (select number from master.dbo.spt_values where type= ' P ') K where number <= len (' 11 011 ') L Result:-----octal conversion decimal-----------------Select SUM (data1) from (Select substring (' 1234567 ', number, 1) *power (8,l  En (' 1234567 ')-number) data1 from (select number from master.dbo.spt_values where type= ' P ') K where number <= Len (' 1234567 ')) L Result: 342391-----16 binary Convert decimal-----------------select SUM (data1) from (Select Case upper (substring (' 4eb7                                                    ', number, 1) if ' A ' then ten when ' B ' then 11                                                     When ' C ' then the ' D ' then 13  When ' E ' and then ' F ' Then the Else SubString (' 4eb7 ', number, 1) end* Power (len (' 4eb7 ')-number) Data1 from (select number from mast er.dbo.spt_values where type= ' P ') K where number <= len (' 4eb7 ') L Result: 20151-----decimal conversion Binary-----------------D Eclare @i int,@s varchar (TEN) Set @i=27set @s= "Select @s=cast (@i%2 as varchar) [email protected],@[email  Protected]/2from (select number from master.dbo.spt_values where type= ' P ' and number<10 and Power (2,number) <@i) Kor Der by number desc Select @s Result: 11011-----Decimal conversion octal-----------------declare @i int,@s varchar (TEN) Set @i=27set @s= "SELECT @ S=cast (@i%8 as varchar) [Email protected],@[email protected]/8from (select number from Master.dbo.spt_ Values where type= ' P ' and number<10 and Power (8,number) <@i) korder by number desc Select @s Result:-----decimal convert hexadecimal----- ------------DECLARE @i int,@s varchar (TEN) Set @i=2379set @s= "Select @s=case when @i%16 between, and then char (@i%16+ Else cast (@i%16 as varchar) END [EMAIL&NBSp;protected],@[email protected]/16from (select number from master.dbo.spt_values where type= ' P ' and number<10 ) Korder by number desc Select @s Result: 94B

Conversion between SQL binaries

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.