CREATE FUNCTION BinaryToDec (@BinaryChar char(10))
RETURNS int
AS
BEGIN
DECLARE @stringLength int,@ReturnValue int,@Index int
DECLARE @CurrentChar char(1)
SET @Index = 0
SET @ReturnValue = 0
SET @stringLength = LEN(@BinaryChar)
While @Index<@stringLength
BEGIN
SET @Index = @Index + 1
SET @CurrentChar = SUBSTRING(@BinaryChar,@Index,1)
IF(@CurrentChar='1' or @CurrentChar='0')
BEGIN
SET @ReturnValue = @ReturnValue + (CAST(@CurrentChar as int) * POWER(2,@stringLength - @Index))
END
END
RETURN @ReturnValue
END