I have created this query for ItemCode generation:
DECLARE @num as nvarchar(20);
DECLARE @max_num as integer;
SET @num =$[$U_Level1.0.0] +$[$U_Level2.0.0] + $[$U_Level3.0.0]
SET @max_num = CASE WHEN NOT EXISTS(SELECT itemcode from OITM where itemcode like @num + '%')
THEN 0 ELSE (SELECT MAX( CAST (REPLACE(Itemcode, @num, '') AS INT)) FROM OITM where itemcode like @num + '%') END
SELECT @num + STUFF(
6 - LEN(CAST(@max_num + 1 as nvarchar (20))),
LEN(CAST(@max_num + 1 as nvarchar (20))),
CAST(@max_num + 1 as nvarchar (20)))
When i'm adding this FMS to UDF field it is works fine (like on screenshot)
But when i'm adding this FMS to ItemCode field and press the magnifying glass, i'm receiving error:
"Internal Error (3006) (Message 131-183)"
I'm also tried to use magic symbol '-' before the item index, but in that case FMS does not work even in my UDF...
Will be appreciate for any help.