2
I have 3 tables:
Person
CREATE TABLE Pessoa (
ID_Pessoa INTEGER PRIMARY KEY IDENTITY (1,1),
ID_Telefone INTEGER FOREIGN KEY REFERENCES Telefone (ID_Telefone),
Nome_PSOA VARCHAR(50) NOT NULL,
CPF_PSOA CHAR(14) NOT NULL,
RG_PSOA VARCHAR(15) NOT NULL,
Classe_PSOA VARCHAR(30) NOT NULL,
Cadastro_Pendente_PSOA BIT
);
Functionary
CREATE TABLE Funcionario (
ID_Funcionario INTEGER PRIMARY KEY IDENTITY (1,1),
ID_Pessoa INTEGER FOREIGN KEY REFERENCES Pessoa (ID_Pessoa) NOT NULL,
ID_Cargo INTEGER FOREIGN KEY REFERENCES Cargo (ID_Cargo),
Email_FUNC VARCHAR(50),
Ramal_FUNC VARCHAR(4),
Horario_Trabalho_FUNC VARCHAR(50) NOT NULL,
Escala_FUNC VARCHAR(25),
Permitir_Visitas_FUNC BIT,
Descricao_FUNC VARCHAR(200)
);
Office
CREATE TABLE Cargo (
ID_Cargo INTEGER PRIMARY KEY IDENTITY (1,1),
ID_Departamento INTEGER FOREIGN KEY REFERENCES Departamento (ID_Departamento) NOT NULL,
Nome_CRGO VARCHAR(50) NOT NULL,
Descricao_CRGO VARCHAR(200)
);
In my application I have a query that returns the following data (respectively): Id_pessoa - Id_funcionario - Pso_name - Cr_name - RG_PSOA - CPF_PSOA
The point is this : When I remove a post from the system I Seto NULL
in the ID_Cargo
all records of Funcionario
that has that role so that I can delete it without referential integrity problems. However, when the query is executed, the DataGridView
returns me only the records that have a ID_Cargo
not null. My goal is, in the field Nome_CRGO
of all records with the ID_Cargo = NULL
, show nothing, but make them appear in the query.
Consultation that did not work :
SELECT TOP 20 dbo.Pessoa.ID_Pessoa AS 'ID',
ID_Funcionario AS 'ID do Funcionário',
Nome_PSOA AS 'Nome',
Nome_CRGO AS 'Cargo',
RG_PSOA AS 'RG',
CPF_PSOA AS 'CPF'
FROM dbo.Pessoa,
dbo.Funcionario,
dbo.Cargo
WHERE dbo.Funcionario.ID_Pessoa = dbo.Pessoa.ID_Pessoa
AND (
dbo.Cargo.ID_Cargo = dbo.Funcionario.ID_Cargo
OR dbo.Funcionario.ID_Cargo = NULL
)
ORDER BY dbo.Pessoa.ID_Pessoa DESC
does the same sql only with left Outer Join
– Rovann Linhalis