 	    SET bit = bit-1;
 	    SET mask = left_shift(cast(2 as bigint),bit);
 	    CASE 
-		WHEN (bit_and(mask,value)=0) THEN SET out = out || ''; 
+		WHEN (bit_and(mask,val)=0) THEN SET out = out || ''; 
 		ELSE SET out = out || (coalesce((select name from FieldMask where value=mask),'')||' ');
 	    END CASE;
 	END WHILE;
     RETURN out;
 END;
 
-CREATE FUNCTION fPhotoFlagsN(value bigint)
+CREATE FUNCTION fPhotoFlagsN(val bigint)
 RETURNS varchar(1000)
 BEGIN
     DECLARE bit int, mask bigint, out varchar(2000);

	    SET bit = bit-1;
	    SET mask = left_shift(cast(2 as bigint),bit);
	    CASE 
		WHEN (bit_and(mask,value)=0) THEN SET out = out || ''; 
		ELSE SET out = out || (coalesce((select name from PrimTarget where value=mask),'')||' ');
	    END CASE;
    END WHILE;
    RETURN out;
END;

CREATE FUNCTION fPrimTarget(name varchar(40))
RETURNS int
BEGIN
	RETURN ( SELECT cast(value as int)
		FROM PrimTarget
		WHERE name = UPPER(name)
		);
END;

CREATE FUNCTION fSecTarget(name varchar(40))
RETURNS int
BEGIN
RETURN ( SELECT cast(value as int)
	FROM SecTarget
	WHERE name = UPPER(name)
	);
END;

CREATE FUNCTION fSecTargetN(value int)
RETURNS varchar(1000)
BEGIN
    DECLARE bit int, mask bigint, out varchar(2000);

    RETURN fHMSbase(deg,default,default);
END;

CREATE  FUNCTION fHMSbase(deg float, truncate int = 0, precision int)
RETURNS varchar(32)
BEGIN
    DECLARE
