delphi
procedure TFRQcentral.DBGrid1TitleClick(Column: TColumn); var ordenando: string; begin ordenando := Column.FieldName; inicio:=formatdatetime('yyyymmdd' ,datetimepicker1.date); fin:=formatdatetime('yyyymmdd' ,datetimepicker2.date); if edcliente.Text <> '' then begin Dmmonitoreo.QCENTRAL.SQL.clear; Dmmonitoreo.QCENTRAL.SQL.Add('select * from central left join acmsub on central.csid=acmsub.csid '); Dmmonitoreo.QCENTRAL.SQL.Add(' left JOIN evento ON CENTRAL.EVENTO = evento.Evento'); Dmmonitoreo.QCENTRAL.SQL.Add(' where ' + 'ACMSUB.clientes LIKE ' + quotedstr('%' + edcliente.Text + '%')); Dmmonitoreo.QCENTRAL.SQL.Add(' and CENTRAL.FECHAN between ' + quotedstr (inicio) + ' and ' + quotedstr(fin)); Dmmonitoreo.QCENTRAL.SQL.Add(' order by ' + (ordenando)); Dmmonitoreo.QCENTRAL.Open; if edcsid.text <> '' then begin Dmmonitoreo.QCENTRAL.SQL.clear; Dmmonitoreo.QCENTRAL.SQL.Add('select * from central left join acmsub on central.csid = acmsub.csid '); Dmmonitoreo.QCENTRAL.SQL.Add(' left JOIN evento ON CENTRAL.EVENTO = evento.Evento '); Dmmonitoreo.QCENTRAL.SQL.Add(' where CENTRAL.CSID like ' + QUOTEDSTR(EDCSID.TEXT + '%')); Dmmonitoreo.QCENTRAL.SQL.Add(' and CENTRAL.FECHAN between ' + quotedstr (inicio) + 'and' + quotedstr(fin)); Dmmonitoreo.QCENTRAL.SQL.add( ' order by '+ (ordenando)); Dmmonitoreo.QCENTRAL.Open; end; end; end;
aunque por ejemplo la columna csid que es el codigo del cliente en la tabla acmsub y tambien en la tabla central, en el query sql les puso como alias csid y csid_1
Espero entiendan la pregunta