INSERT INTO [dbo].[T_EXTRA_UI_ACTION_PARAMS]
           ([ExtraUiActionParamsID]
           ,[ExtraUiCommand]
           ,[Name]
           ,[ParamDescription]
           ,[IsOutput]
           ,[ParamValue])
SELECT
           NEWID()--<ExtraUiActionParamsID, uniqueidentifier,>
           ,tt.ExtraUiCommandID--<ExtraUiCommand, uniqueidentifier,>
           ,T.c.value('declare namespace lx="lexem"; ./@name', 'varchar(max)')--<Name, varchar(255),>
           ,T.c.value('declare namespace lx="lexem"; ./@name', 'varchar(max)')--<ParamDescription, varchar(255),>
           ,0--<IsOutput, bit,>
           ,cast(T.c.query('declare namespace lx="lexem"; .') as varchar(max))--<ParamValue, text,>
from
(
    select euc.ExtraUiCommandID, cast(euc.FilterValue as xml) as xmlText
    from T_EXTRA_UI_COMMAND euc
    where euc.FilterValue is not null
            and
        euc.CommandType in (1, 2, 3)
) tt
cross apply tt.xmlText.nodes('declare namespace lx="lexem"; //lx:UserQueryOperand') T(c)
GO



update euap
set euap.ParamValue = '<lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="' + cast(ea.[Index]as varchar(max)) + '" /></lx:Path>'
from T_EXTRA_UI_ACTION_PARAMS euap
    join T_EXTRA_UI_COMMAND euc on euc.ExtraUiCommandID = euap.ExtraUiCommand
    join T_ENTITIES_ATTRIBUTES ea on ea.EntityID = euc.Entities
            and
        ea.AttributeType = -1
where euap.Name = 'ID'
        and
    euc.FilterValue is not null
        and
    euc.CommandType in (1, 2, 3)
GO