Easiest way to eliminate NULLs in SELECT DISTINCT?

前端 未结 8 537
我寻月下人不归
我寻月下人不归 2020-12-10 01:28

I am working on a query that is fairly similar the following:

CREATE TABLE #test (a char(1), b char(1))

INSERT INTO #test(a,b) VALUES 
(\'A\',NULL),
(\'A\',         


        
8条回答
  •  离开以前
    2020-12-10 01:42

    I'll just put here a mix of two answers that solved my issue, because my View was more complex

        --IdCompe int,
        --Nome varchar(30),
        --IdVanBanco int,
        --IdVan int
        --FlagAtivo bit,
        --FlagPrincipal bit
    
        select IdCompe
               , Nome
               , max(IdVanBanco)
               , max(IdVan)
               , CAST(MAX(CAST(FlagAtivo as INT)) AS BIT) FlagAtivo
               , CAST(MAX(CAST(FlagPrincipal as INT)) AS BIT) FlagPrincipal
        from VwVanBanco
               where IdVan = {IdVan} or IdVan is null
               group by IdCompe, Nome order by IdCompe asc
    

    Thanks to mosty mostacho and kenwarner

提交回复
热议问题