Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Bases de datos > Tablas planas
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 09-09-2007
[FGarcia] FGarcia is offline
Miembro Premium
 
Registrado: sep 2005
Ubicación: Cordoba, Veracruz, México
Posts: 1.123
Poder: 20
FGarcia Va por buen camino
Consulta con campos devueltos NULL

Hola!

Esta consulta se realiza cada hora mediante un timer o tambien se puede hacer mediante un boton pasandole los parametros iHora y eHora

Código Delphi [-]
procedure TfrmMain.ActualizaCadaHora(iHora: string; eHora: string) ;
var
  estaHora: Tdatetime;
  consultaVacia: Boolean;
begin
  consultaVacia := False;
  with QyHora do
    begin
      Close ;
      SQL.Clear ;
      SQL.Add('SELECT COUNT(*) AS HSacos, ' +
                'SUM (Peso) AS [HTotal] ' +
                'FROM Captura ' +
                'WHERE (HoraFecha BETWEEN :FIni AND :FFin)');
      Parameters.ParamByName('FIni').Value := iHora;
      Parameters.ParamByName('FFin').Value := eHora;
      Open ;
      if (QyHora.RecordCount = 0) then
        consultaVacia := True;
    end;
  if not consultaVacia then
    begin
      //Convierto la cadena iHora a un formato de datetime
      estaHora := StrToDateTime(iHora);
      DecodeTime(estaHora, miHora,miMin,miSeg,miMseg);
      case miHora of
      0:  begin
            StringGrid1.Cells[1,1] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,1] := QyHora.FieldValues['HTotal'];
          end;
      1:  begin
            StringGrid1.Cells[1,2] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,2] := QyHora.FieldValues['HTotal'];
          end;
      2:  begin
            StringGrid1.Cells[1,3] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,3] := QyHora.FieldValues['HTotal'];
          end;
      3:  begin
            StringGrid1.Cells[1,4] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,4] := QyHora.FieldValues['HTotal'];
          end;
      4:  begin
            StringGrid1.Cells[1,5] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,5] := QyHora.FieldValues['HTotal'];
          end;
      5:  begin
            StringGrid1.Cells[1,6] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,6] := QyHora.FieldValues['HTotal'];
          end;
      6:  begin
            StringGrid1.Cells[1,7] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,7] := QyHora.FieldValues['HTotal'];
            Stringgrid1.TopRow := 7;
          end;
      7:  begin
            StringGrid1.Cells[1,8] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,8] := QyHora.FieldValues['HTotal'];
          end;
      8:  begin
            StringGrid1.Cells[1,9] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,9] := QyHora.FieldValues['HTotal'];
          end;
      9:  begin
            StringGrid1.Cells[1,10] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,10] := QyHora.FieldValues['HTotal'];
          end;
      10: begin
            StringGrid1.Cells[1,11] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,11] := QyHora.FieldValues['HTotal'];
          end;
      11: begin
            StringGrid1.Cells[1,12] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,12] := QyHora.FieldValues['HTotal'];
          end;
      12: begin
            StringGrid1.Cells[1,13] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,13] := QyHora.FieldValues['HTotal'];
          end;
      13: begin
            StringGrid1.Cells[1,14] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,14] := QyHora.FieldValues['HTotal'];
          end;
      14: begin
            StringGrid1.Cells[1,15] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,15] := QyHora.FieldValues['HTotal'];
            Stringgrid1.TopRow := 15;
          end;
      15: begin
            StringGrid1.Cells[1,16] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,16] := QyHora.FieldValues['HTotal'];
          end;
      16: begin
            StringGrid1.Cells[1,17] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,17] := QyHora.FieldValues['HTotal'];
          end;
      17: begin
            StringGrid1.Cells[1,18] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,18] := QyHora.FieldValues['HTotal'];
          end;
      18: begin
            StringGrid1.Cells[1,19] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,19] := QyHora.FieldValues['HTotal'];
          end;
      19: begin
            StringGrid1.Cells[1,20] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,20] := QyHora.FieldValues['HTotal'];
          end;
      20: begin
            StringGrid1.Cells[1,21] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,21] := QyHora.FieldValues['HTotal'];
          end;
      21: begin
            StringGrid1.Cells[1,22] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,22] := QyHora.FieldValues['HTotal'];
          end;
      22: begin
            StringGrid1.Cells[1,23] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,23] := QyHora.FieldValues['HTotal'];
            Stringgrid1.TopRow := 23;
          end;
      23: begin
            StringGrid1.Cells[1,24] := QyHora.FieldValues['HSacos'];
            StringGrid1.Cells[2,24] := QyHora.FieldValues['HTotal'];
          end;
      end;
    end;
end;

El problema radica en que si dentro de el periodo comprendido entre iHora y eHora no hay ningun registro el campo HTotal es null por lo tanto cuando quiero asignar el valor correspondiente a la rejilla (StringGrid1) me devuelve un error de "Cast"

---------------------------
Jugoso
---------------------------
Could not convert variant of type (Null) into type (String)
---------------------------
Aceptar
---------------------------

Estuve buscando en el foro y no encontre alguna respuesta para ACCESS ya se que no les gusta access pero ... a ver si alguien me ayuda.

Saludos!
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
FOR XML + SQL SERVER 200 y campos con valor null Enan0 SQL 2 07-08-2007 00:45:55
Campos null. Asignación jlrbotella Conexión con bases de datos 3 23-03-2007 16:26:27
Campos Not null de MSQL emeritos SQL 6 13-01-2007 08:29:02
Unir contenido de campos omitiendo los null el-otro SQL 2 28-09-2004 08:39:23
suma de fila con campos a null en una consulta sql soyhugo Varios 8 02-02-2004 19:01:33


La franja horaria es GMT +2. Ahora son las 17:11:32.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi