MySQL Forums
Forum List  »  Microsoft SQL Server

Re: Conversion problem with cast function
Posted by: Alberto Molero
Date: December 05, 2012 01:50AM

I finally found a solution...(but it's not elegant...) i created another function to convert an integer value to binary(4) value.

CREATE DEFINER=`root`@`localhost` FUNCTION `ITOB`(pNum Integer) RETURNS varbinary(4)
BEGIN
Declare cResult char(32);
Declare bit1 Integer Default 0;
Declare bit2 Integer Default 0;
Declare bit3 Integer Default 0;
Declare bit4 Integer Default 0;

Set cResult = LPAD(BIN(pNum), 32, 0);

Set bit1 = Conv(Substring(cResult, 1, 8), 2, 10);
Set bit2 = Conv(Substring(cResult, 9, 8), 2, 10);
Set bit3 = Conv(Substring(cResult, 17, 8), 2, 10);
Set bit4 = Conv(Substring(cResult, 25, 8), 2, 10);

RETURN Cast(Concat(Char(bit1), Char(bit2), Char(bit3), Char(bit4)) As binary(4));
END

Thanks for all :)

Options: ReplyQuote


Subject
Written By
Posted
Re: Conversion problem with cast function
December 05, 2012 01:50AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.