/****** Script do comando SelectTopNRows de SSMS  ******/
SELECT 
	CONCAT('
	INSERT INTO TBESTOQUE_TRANSACAO_ITEM (
        TABELA,
        TABELA_ID,
        TABELA_NIVEL,
        ESTABELECIMENTO_CODIGO,
        LOCALIZACAO_CODIGO,
        PRODUTO_CODIGO,
        CONTROLE,
        DATA,
        DOCUMENTO,
        NFS_ITEM_CONTROLE,
        NFE_ITEM_CONTROLE,
        OPERACAO_CODIGO,
        TIPO,
        QUANTIDADE,
        REMESSA_ITEM_CONTROLE,
        T01,
        T02,
        T03,
        T04,
        T05,
        T06,
        T07,
        T08,
        T09,
        T10,
        T11,
        T12,
        T13,
        T14,
        T15,
        T16,
        T17,
        T18,
        T19,
        T20,
        CUSTO_UNITARIO,
        TRANSACAO_CONTROLE,
        CONSUMO,
        USUARIO_CODIGO,
        USUARIO_DATA,
        TURNO_CODIGO,
        CENTRO_DE_CUSTO,
        OBSERVACAO,
        ESPUMACAO,
        CLASSIFICACAO,
        REVISAO_CONTROLE,
        EMPRESA_CODIGO,
        CUSTO_MEDIO,
        ESTOQUE_TRANSACAO_REGRA_ID,
        CONFERENCIA,
        PECA_ID,
        OPERADOR
    ) VALUES(
        0,
        0,
        0,
        ',1,',
        2,
        (select first 1 p.codigo from tbproduto p where p.modelo_codigo = ',MODELO,' and p.cor_codigo = ',[Cor],'),'
        ,'0, current_date, ''24102022'', 0, 0, ''IMP'', ''E'','
        ,[Estoque],',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,
        CURRENT_DATE,
        0,
        '''',
        ''REGISTRO IMPORTADO'',
        ''0'',
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0
    );') AS SQL,

	G.*

from(
	SELECT [Codigo]  + 1000 as MODELO
			,[Cor]
			,[Und]
			,[Estoque],
			0 PTAMANHO
	FROM [AlphaInd].[dbo].[viewEstoqueAlmox]
	where [Estoque] > 0.001
) G