Fórum unir select #423667
14/09/2012
0
Preciso fazer um select onde a condição pode ser um nome específico de uma coluna (select 1)
ou trazer todos os campos da coluna (select 2)
select 1
MyQuery1.SQL.add('select nome, cpf');
MyQuery1.SQL.add('from aluno');
MyQuery1.SQL.add('where nome =: parametro');
MyQuery1.Params[0].Value := Combobox1.Text;
select 2
MyQuery1.SQL.add('select nome, cpf');
MyQuery1.SQL.add('from aluno');
Como posso unir estes dois select. No form(Delphi) tem um CheckBox, que se for selecionado indica que o usuário quer exibir todos os alunos(select 2), ou ele clica em um Combobox onde escolhe o nome a ser exibido(select 1)
Claudivan Lopes
Curtir tópico
+ 0Posts
26/09/2012
Joel Rodrigues
Se tiver duvida com relação a implementação, é só avisar.
Gostei + 0
26/09/2012
Claudia Nogueira
Preciso fazer um select onde a condição pode ser um nome específico de uma coluna (select 1)
ou trazer todos os campos da coluna (select 2)
select 1
MyQuery1.SQL.add('select nome, cpf');
MyQuery1.SQL.add('from aluno');
MyQuery1.SQL.add('where nome =: parametro');
MyQuery1.Params[0].Value := Combobox1.Text;
select 2
MyQuery1.SQL.add('select nome, cpf');
MyQuery1.SQL.add('from aluno');
Como posso unir estes dois select. No form(Delphi) tem um CheckBox, que se for selecionado indica que o usuário quer exibir todos os alunos(select 2), ou ele clica em um Combobox onde escolhe o nome a ser exibido(select 1)
if (not CbTodos.Checked) and (Combobox1.Text = '') then
begin
ShowMessage('Escolha o aluno');
Combobox1.SetFocus;
Exit;
end;
MyQuery1.Close;
MyQuery1.SQL.Clear;
if CbTodos.Checked then
begin
MyQuery1.SQL.add('select nome, cpf');
MyQuery1.SQL.add('from aluno');
end
else
begin
MyQuery1.SQL.add('select nome, cpf');
MyQuery1.SQL.add('from aluno');
MyQuery1.SQL.add('where nome =: parametro');
MyQuery1.Params[0].Value := Combobox1.Text;
end;
MyQuery1.Open;
Gostei + 0
26/09/2012
Claudia Nogueira
Gostei + 0
27/09/2012
Joel Rodrigues
MyQuery1.SQL.add('select nome, cpf');
MyQuery1.SQL.add('from aluno');
if (not CbTodos.Checked) then
begin
if comboAlunos.Text = '' then
begin
Application.MessageBox('Selecione um aluno!', 'Atenção', MB_OK+MB_ICONWARNING);
comboAlunos.SetFocus();
Exit;
end
MyQuery1.SQL.add('where nome =: parametro');
MyQuery1.Params[0].Value := Combobox1.Text;
end
MyQuery1.Open;
Ou seja, o SELECT * FROM é feito independente do filtro. Caso o usuário deseje filtrar, aí sim adiciona-se a cláusula where.
Boa sorte.
Gostei + 0
27/09/2012
Alisson Santos
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)