SELECT 
	  
	CONCAT('update or insert into TBPRODUTO_CONTABIL (PRODUTO_CODIGO, CONTACONTABIL_ESTOQUE, CONTACONTABIL_CONSUMO, CUSTOUNITARIO_PADRAO, CUSTOUNITARIO_MEDIO, CUSTOUNITARIO_ULTIMO, CREDITOPIS, CREDITOCOFINS, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, IMPOSTO_CUSTO, ICMS, IPI, FRETE, FINANCEIRO) ',
		'values ((select first 1 p.codigo from tbproduto p where p.modelo_imp = ', a.[Codigo]  + 1000,' and p.cor_codigo = ',b.Cor,'), null, null, ',a.PrCusto,', ',a.PrCusto,', ',a.PrCusto,', 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) matching (PRODUTO_CODIGO);' 
	) as SQL,

	a.*

FROM [Alphaind 4].[dbo].[Almox] a, [Alphaind 4].[dbo].[Almox_Itens] b
where a.Codigo = b.Almox
and a.PrCusto > 0