Show item description only when equal to only appear as " null " or " No Description "

Asked

Viewed 21 times

0

In Sqlserver, I need to appear in the Description column only values that have all the same values grouped in group by, otherwise show as null or Sem Descrição, when you have a different description as in the item 00500373.

Example below

inserir a descrição da imagem aqui

Should appear like this:

Item = 00500237 Descricao = AJUSTE DE ESTOQUE

Item = 00500373 Descricao = Null

1 answer

0

I think something like:

SELECT Item, 
       (CASE WHEN EXISTS (SELECT 1 FROM sua_tabela aux WHERE aux.Item = sua_tabela.Item AND aux.Descricao <> sua_tabela.Descricao)
             THEN NULL
             ELSE aux.Descricao
        END) AS Descricao 
FROM sua_tabela 

can serve you.
Post a table definition, with the respective Inserts, so it can be tested.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.