![]() |
Consulta sql con rango de fechas
Hola al foro
Tengo una tabla paradox con campos mes y año - Quiero filtrar toda la información entre el 11/2003 y el 01/2004 ¿Como puedo realizar esta consulta? gracias por la ayuda JGutti |
Código:
procedure TForm1.Button1Click(Sender: TObject); |
Otra opción:
Select * From Tabla Where ano*100+mes >= 200311 and ano*100+mes <= 200401 |
consulta de tiempo
Aquí pienso que te doy respuesta, es un procedimiento que realiza hace tiempo, lo mando completo y cojan lo que les sirva.
Var Str1:String; var1 :Variant; WPuesto :Boolean; begin {filtrado de la base de datos } OldEvento :=CBoxEventos.ItemIndex; OldResp :=CBoxResponsable.ItemIndex; WPuesto :=False; With ModuloDatos do Begin MyQuery.Active :=False; MyQuery.SQL.Clear; MyQuery.SQL.Add('Select * from AcInd a'); If CBResponsable.Checked And ( CBoxResponsable.Text <> '' ) Then Begin var1 :=CBoxResponsable.text; Str1 :='Where a.RESP =''' + VarToStr( Var1 ) + ''''; MyQuery.SQL.Add( Str1 ); WPuesto :=True; End; If CBEventos.Checked And ( CBoxEventos.Text <> '' ) Then Begin var1 :=CBoxEventos.text; If Not WPuesto Then Begin Str1 :='Where a.EVENTOE =''' + VarToStr( Var1 ) + ''''; WPuesto :=True; End Else Str1 :='And a.EVENTOE =''' + VarToStr( Var1 ) + ''''; MyQuery.SQL.Add( Str1 ); End; If CBEstado.Checked And ( CBoxEstado.Text <> '' ) Then Begin var1 :=CBoxEstado.text; If Not WPuesto Then Begin Str1 :='Where a.ESTADO =''' + VarToStr( Var1 ) + ''''; WPuesto :=True; End Else Str1 :='And a.ESTADO =''' + VarToStr( Var1 ) + ''''; MyQuery.SQL.Add( Str1 ); End; If FSelecc.ItemIndex = 0 Then Begin If CBFinicial.Checked Then Begin MyQuery.Params.CreateParam(ftdate, 'FromDate', ptInputOutput); MyQuery.Params.ParambyName('FromDate').AsDate :=FechaInicial.Date; If Not WPuesto Then Begin Str1 :='Where ( a.FECHAE >= :FromDate )'; WPuesto :=True; End Else Str1 :='And ( a.FECHAE >= :FromDate )'; MyQuery.SQL.Add( Str1 ); End; If CBFFinal.Checked Then Begin MyQuery.Params.CreateParam(ftInteger, 'ToDate', ptInputOutput); MyQuery.Params.ParamByName('ToDate').AsDate :=FechaFinal.Date; If Not WPuesto Then Begin Str1 :='Where ( a.FECHAE <= :ToDate )'; WPuesto :=True; End Else Str1 :='And ( a.FECHAE <= :ToDate )'; MyQuery.SQL.Add( Str1 ); End; End Else Begin If CBFinicial.Checked Then Begin MyQuery.Params.CreateParam(ftdate, 'FromDate', ptInputOutput); MyQuery.Params.ParambyName('FromDate').AsDate :=FechaInicial.Date; If Not WPuesto Then Begin Str1 :='Where ( a.FECHAC >= :FromDate )'; WPuesto :=True; End Else Str1 :='And ( a.FECHAC >= :FromDate )'; MyQuery.SQL.Add( Str1 ); End; If CBFFinal.Checked Then Begin MyQuery.Params.CreateParam(ftInteger, 'ToDate', ptInputOutput); MyQuery.Params.ParamByName('ToDate').AsDate :=FechaFinal.Date; If Not WPuesto Then Begin Str1 :='Where ( a.FECHAC <= :ToDate )'; WPuesto :=True; End Else Str1 :='And ( a.FECHAC <= :ToDate )'; MyQuery.SQL.Add( Str1 ); End; End; MyQuery.SQL.Add('Order by a.COD, a.RESP, a.EVENTOE, a.ESTADO'); MyQuery.Active :=True; LbCant.Caption :=IntToStr( MyQuery.RecordCount ); End; Cualquier aclaración tratare de darle respuesta, siempre que sea específico |
Otra manera...
Hola!
Código:
Query1.Close; |
Me parece el de Nuria un ejemplo muy sencillo pero una pequeña acotacion:
En la linea : Query1.ParamByName('ultfec').AsDate := '01/01/2004'; coloca: Query1.ParamByName('ultfec').AsDate := '31/01/2004'; asi te toma tambien los del mes 01 |
La franja horaria es GMT +2. Ahora son las 06:02:26. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi