0

I have the following view:

ALTER VIEW [dbo].[vw_RelInclusaoGeralCivil]
AS
SELECT   
DISTINCT   
    m.Nome AS MunicipioNome, 
    au.Nome UsuarioNome,
    s.TipoId AS SolicitacaoTipoId
FROM                    
    Solicitacao s
INNER JOIN
    Unidade u 
ON
    s.UnidadeEntregaId = u.Id
INNER JOIN
    Endereco e
ON
    u.EnderecoId = e.Id
INNER JOIN
    [IBGE.Municipio] m
ON
    e.CodMunicipio = m.CodMunicipio
INNER JOIN
    Terminal t
ON
    u.Id = t.UnidadeId
INNER JOIN
    Auditoria a
ON
    t.Id = a.TerminalId
INNER JOIN
    [Acesso.Usuario] au
ON
    a.UsuarioId = au.Id
WHERE
    s.TipoId <> 5
AND
    a.TerminalId IS NULL
GO

The Solicitacao table:

Id | UnidadeEntregaId | TipoId
2  |        4         |   1

The Unidade table:

Id | EnderecoId | 
4  |     5      |

The Endereco table:

Id | CodMunicipio | 
5  |  5208707     |

The IBGE.Municipio table:

CodMunicipio | Nome
5208707      | GOIANIA

The Terminal table(I need this table to get in the Acesso.Usuario table):

Id        | Codigo | 
1         | 0001   |  

The Auditoria table(all TerminalId in Auditoria table are null, but i also need it to get in Acesso.Usuario):

TerminalId | UsuarioId |
NULL       |    31     |

And the Acesso.Usuario table:

Id | Nome
31 | Usuario Master

What can I do to show the Solicitacao in my view?
Thanks

2
Contributors
1
Reply
16
Views
2 Years
Discussion Span
Last Post by bnmng
0

You might get what you want by using a LEFT JOIN instead of the first INNER JOIN.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.