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