Hi Alex,
Sorry my bad english...
After look the function are you created on the MS-SQL Server, I need to confess I got a little lazy to understand...
But, now looking for the function on the google I found the manual of MySQL, more easy to understand
well, I wrote this ...
Code:
--drop function bit_string;
--drop function bit_count;
create function bit_string(pValue int) returning char(256);
define vI int;
define vX int;
define vBit smallint;
define vRes char(300);
--set debug file to "/tmp/sp.out";
--trace on;
let vRes="";
let vI=0;
while vI <= 30
let vX=pow(2,vI);
let vBit=sysmaster:bitval(pValue,vX);
let vRes=vBit||trim(vRes);
let vI=vI+1;
end while;
return vRes;
end function
document "Return a string with bit from parameter pValue"
;
grant execute on procedure bit_string to public
;
create function bit_count(pValue int) returning smallint;
define vI int;
define vX int;
define vBit smallint;
define vRes smallint;
let vRes=0;
let vI=0;
while vI <= 30
let vX=pow(2,vI);
let vBit=sysmaster:bitval(pValue,vX);
let vRes=vBit+vRes;
let vI=vI+1;
end while;
return vRes;
end function
document "Return a number with how much bits are active from parameter pValue"
;
grant execute on procedure bit_count to public
;
If you are using IDS 7.31 , you will need to adapt:
- change :
"create function" >>> "create procedure"
"end function" >>> "end procedure"
- and this, don't ask me why... if you not change will get error on the execution.
"while vI <= 30" >>>> "while vI <= 29"