SQL Server: converts a 6-byte hexadecimal page number into a format Function

Source: Internet
Author: User

Sometimes we need to know the file number and page number of a record stored in the table, but after our own query, it is a hexadecimal page number, then how can we calculate the "file number" and "page number" of the Record Based on the hexadecimal page number?
The following functions help us solve this problem: return the [X: XX] format
Alter   Function Convert_page_nums ( @ Page_num   Binary ( 6 ))
Returns   Varchar ( 11 )
As  
Begin
Return (
Convert ( Varchar ( 2 ),(
Convert ( Int , Substring ( @ Page_num , 6 , 1 )) *   Power ( 2 , 8 )
) +
( Convert ( Int , Substring ( @ Page_num , 5 , 1 )))
) +   ' : '   +
Convert ( Varchar ( 11 ),
( Convert ( Int , Substring ( @ Page_num , 4 , 1 )) *   Power ( 2 , 24 )) +  
( Convert ( Int , Substring ( @ Page_num , 3 , 1 )) *   Power ( 2 , 16 )) +
( Convert ( Int , Substring ( @ Page_num , 2 , 1 )) *   Power ( 2 , 8 )) +
( Convert ( Int , Substring ( @ Page_num , 1 , 1 )))
)
)
End

Then you can run the following SELECT statement to call this function.
Select DBO. convert_page_nums (0x6e0000000100 );
 
The following result is displayed: 1: 110

---------------------- End --------------------------

Related Article

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.