Cita:
Empezado por jonydread
como puedo unir campos para ver si existe campo en ambas tablas
por ejemplo en campo1 de tabla1 y campo1 de tabla2 si existe el numero 1
|
Hola jonydread.
Si queres verificar si existen ocurrencias en ambas tablas podes hacer:
Código Delphi
[-]
function Tu_Form.ExisteEnAmbas(aValue: Variant): Boolean;
begin
with ZQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('SELECT COUNT(*) AS EXISTE');
SQL.Add('FROM ASIGNADOSA T1, ASIGNADOSB T2');
SQL.Add('WHERE T1.SIERRAS = :PVALUE AND T2.SIERRAS = :PVALUE');
ParamByName('PVALUE').Value := aValue;
Open;
Result := FieldByName('EXISTE').AsInteger > 0;
Close
end
end;
...
begin
if ExisteEnAmbas(Valor_Condicion) then
ShowMessage('Existe')
else
ShowMessage('No existe');
...
Si deseas mostrar todas las ocurrencias que coincidan con un valor:
Código Delphi
[-]
...
with ZQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('SELECT * '); SQL.Add('FROM ASIGNADOSA T1, ASIGNADOSB T2');
SQL.Add('WHERE T1.SIERRAS = :PVALUE AND T2.SIERRAS = :PVALUE');
ParamByName('PVALUE').Value := Valor_Condicion;
Open;
end
...
Saludos