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

Respuesta
 
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
  #2  
Antiguo 09-09-2007
Avatar de eduarcol
[eduarcol] eduarcol is offline
Miembro Premium
 
Registrado: ago 2003
Ubicación: En los estados Zulia y Merida de Venezuela
Posts: 4.151
Poder: 25
eduarcol Va por buen camino
Hola se que esta no es la solucion, pero porq en lugar de stringgrid no usas un dbgrid, te ahorrarias mas trabajo
__________________
...Yo naci en esta ribera del arauca vibr@d0r
Soy hermano de la espuma,
de la garza, de la rosa y del sol...
Viva Venezuela
Responder Con Cita
  #3  
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
Si eso lo se, lo que pasa es que estoy tabulando por horas y quiero saber los datos en cada hora

____________________
Hora | Sacos | Total |
____________________
10 - 11 | 1550 | 9876 |
____________________
11 - 12 | 2340 | 10657|
____________________
12 - 13 | 0 | 0|
____________________
13 - 14 | 12| 480|
____________________

Usar un dbgrid para la columna hora seria mas engorroso ¿no crees?
Responder Con Cita
  #4  
Antiguo 09-09-2007
Avatar de eduarcol
[eduarcol] eduarcol is offline
Miembro Premium
 
Registrado: ago 2003
Ubicación: En los estados Zulia y Merida de Venezuela
Posts: 4.151
Poder: 25
eduarcol Va por buen camino
nop, ese valor se lo puedes dar en el evento ongettext del field hora de la consulta, engorroso es el stringgrid, bueno por lo menos a mi me da comezon utilizarlo
__________________
...Yo naci en esta ribera del arauca vibr@d0r
Soy hermano de la espuma,
de la garza, de la rosa y del sol...
Viva Venezuela
Responder Con Cita
  #5  
Antiguo 10-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
Bueno se convirtio en capricho usar el stringgrid y la unica solucion que encontre fue esta

Código Delphi [-]
//cree una variable local
esteTotal: string;
 
//antes de asignar los datos al string grid pruebo el valor del campo devuelto HTotal
if QyHora.Fields.FieldByName('HTotal').IsNull  then
        esteTotal := '0'
      else
        esteTotal := QyHora.FieldValues['HTotal'];
 
//Asigno el valor de esteTotal al stringgrid
case of estaHora of
0: begin
       StringGrid1.Cells[1,18] := QyHora.FieldValues['HSacos'];
       StringGrid1.Cells[2,18] := esteTotal;
    end;
.
.
.
.
23: begin
       StringGrid1.Cells[1,18] := QyHora.FieldValues['HSacos'];
       StringGrid1.Cells[2,18] := esteTotal;
     end;
end;

Aun asi, si alguien conoce un modo mas elegante de hacer esto se agradece.
Responder Con Cita
Respuesta



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 00:48:34.


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