select uc.UserContextID 
INTO #Context
from VCLIB.T_USER_CONTEXTS uc
join VCLib.T_ENTITIES e on e.EntityID = uc.EntityID 
where e.EntName = 'DESTINATION_EXECUTE_ELEMENT' and uc.Context = 'DestinationContext'

select '{DestExecuteElementStatus / Status}' as AttributePath, 'Статус' as DisplayName,0 as ColumnIndex,90 as ColumnWidth,1 as Visible,0 as SortingIndex,0 as Sorting
into #Columns
union select '{HospitalDestination / CName}', 'Лечебное назначение',3,697,1,0,0
union select '{HospitalDestination / AmbulanceCard / Patient / FIO}', 'ФИО',1,218,1,0,1
union select '{ElementText}', 'Время',2,110,1,1,1

delete from 
VCLib.T_USER_COLUMNS where UserContextID in (select UserContextID from #Context) 

INSERT INTO [VCLib].[T_USER_COLUMNS]
           ([UserColsID]
           ,[AttributePath]
           ,[DisplayName]
           ,[ColumnIndex]
           ,[ColumnWidth]
           ,[Visible]
           ,[SortingIndex]
           ,[Sorting]
           ,[UserContextID])
select		newid()
           ,[AttributePath]
           ,[DisplayName]
           ,[ColumnIndex]
           ,[ColumnWidth]
           ,[Visible]
           ,[SortingIndex]
           ,[Sorting]
           ,[UserContextID]
from #Columns cc
join #Context c on c.UserContextID is not null


drop table #Columns
drop table #Context