> For the complete documentation index, see [llms.txt](https://suporte-conttrade.gitbook.io/instalacoes-reinstalacoes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://suporte-conttrade.gitbook.io/instalacoes-reinstalacoes/instalacao-plug-sales/criando-o-numerador-do-psid-no-conttrade-erp.md).

# Criando o numerador do PsId no CONTTRADE ERP

`select PsId from Proser`

<figure><img src="/files/nIPQyvq8akIc6QrWoyFS" alt=""><figcaption></figcaption></figure>

## Criando Trigger para o PsId

Criar a Trigger no SQL para Numerar o PsId. \
Abrir o SQL, selecionar o banco do Cliente e New Query e rodar o UPDATE abaixo.

```
CREATE TRIGGER tr_sales ON PROSER
after INSERT
AS
BEGIN
  update PROSER
      set PsId = (Select Coalesce(Max(PsId), 0) + 1 from PROSER)
  from Proser
  where PsCdg = (select top 1 i.PsCdg from inserted i) 
END
```

<figure><img src="/files/4ShFkZGLlLbPKN9EZd3c" alt=""><figcaption></figcaption></figure>

## &#x20;Numerar os Produtos existentes

```
UPDATE PROSER
   SET PROSER.PsID = x.NewPsId
  FROM (
    SELECT ROW_NUMBER() OVER (ORDER BY PSCDG) AS NewPsId, PsCdg
      FROM PROSER V
  ) x
 WHERE PROSER.PsCdg = x.PsCdg
```

&#x20;

<figure><img src="/files/CCTGka0Lk2IckMhsumgj" alt=""><figcaption></figcaption></figure>
