Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Variable String cambia de valor a '' (https://www.clubdelphi.com/foros/showthread.php?t=74084)

oscarac 30-05-2011 04:06:29

Variable String cambia de valor a ''
 
buenas noches

tengo un problema

estoy haciendo este query
Código Delphi [-]
      StrSql := 'Select T.empresa, C.TipoConsumo, C.Tdc, C.Doc, C.f_Doc, C.Hora, C.Aux, T.Descl As Trabajador, C.TOT, A.Descl As Producto ' +
                ' from ((( ' +
                'tblConsumoC C With (noLock) ' +
                'Left Join tblConsumoD D With (noLock) on (C.TDC = D.TDC and C.DOC = D.DOC)) ' +
                'Left Join tblTrabajador T With (noLock) on C.Aux = T.KOD) ' +
                'Left Join TblArticulo A With (noLock) on D.KOD = A.KOD) ' +
                ' Where C.F_DOC Between ' + QuotedStr(FormatDateTime('DD/MM/YYYY', dtFechaIni.Date)) + ' and ' +
                QuotedStr(FormatDateTime('DD/MM/YYYY', dtFechaFin.Date)) + ' and TipoConsumo = ' + QuotedStr('K');
 
      if rgEmpresa.ItemIndex <> 0 then
        StrSql := StrSql + ' and C.Empresa = ' + QuotedStr(IntToStr(rgEmpresa.itemindex)) +
            ' Order by T.Empresa, C.TipoConsumo, T.Descl, C.Tdc, C.Doc'
      Else
        StrSql := StrSql + ' Order by T.Empresa, C.TipoConsumo, T.Descl, C.Tdc, C.Doc'

cuando llega a esta parte

Código Delphi [-]
 
      if rgEmpresa.ItemIndex <> 0 then
        StrSql := StrSql + ' and C.Empresa = ' + QuotedStr(IntToStr(rgEmpresa.itemindex)) +
            ' Order by T.Empresa, C.TipoConsumo, T.Descl, C.Tdc, C.Doc'
      Else
        StrSql := StrSql + ' Order by T.Empresa, C.TipoConsumo, T.Descl, C.Tdc, C.Doc'

la variable StrSql se convierte en '' (blanco)


alguien sabe porque?

P.D. la variable strSql es de tipo String. ya probe con wideString y tambien pasa lo mismo

saludos

Al González 30-05-2011 06:58:53

La respuesta puede surgir al examinar el código completo de esa rutina. ¿Podríamos? :)

oscarac 30-05-2011 07:14:02

claro que si
aunque ya lo cambie de otra forma

Código Delphi [-]
procedure TfrmReporteConsumo.btnGrabarClick(Sender: TObject);
var StrSql :WideString;
begin
  StrSql := '';
  if (rgTipoVenta.ItemIndex = 0) and (rgEmpresa.ItemIndex = 0) Then
    begin
        StrSql := 'Select T.empresa, C.TipoConsumo, C.Aux, T.Descl As Trabajador, Sum (C.TOT) As Total  ' +
                ' from ' +
                'tblConsumoC C ' +
                'Left Join tblTrabajador T on C.Aux = T.KOD ' +
                ' Where C.F_DOC Between ' + QuotedStr(FormatDateTime('DD/MM/YYYY', dtFechaIni.Date)) + ' and ' +
                QuotedStr(FormatDateTime('DD/MM/YYYY', dtFechaFin.Date)) + ' and TipoConsumo = ' + QuotedStr('K') +
                iif (edtTrabajador.Text = '', '', ' and C.AUX = ' + QuotedStr(edtTrabajador.text)) +
                ' order by T.Empresa, T.Descl, C.Tdc, C.Doc'
    end;
  if (rgTipoVenta.ItemIndex = 0) and (rgEmpresa.ItemIndex <> 0) Then
    begin
        StrSql := 'Select T.empresa, C.TipoConsumo, C.Aux, T.Descl As Trabajador, Sum (C.TOT) As Total  ' +
                ' from ' +
                'tblConsumoC C ' +
                'Left Join tblTrabajador T on C.Aux = T.KOD ' +
                ' Where C.F_DOC Between ' + QuotedStr(FormatDateTime('DD/MM/YYYY', dtFechaIni.Date)) + ' and ' +
                QuotedStr(FormatDateTime('DD/MM/YYYY', dtFechaFin.Date)) + ' and TipoConsumo = ' + QuotedStr('K') +
                iif (edtTrabajador.Text = '', '', ' and C.AUX = ' + QuotedStr(edtTrabajador.text)) +
                ' and T.Empresa = ' + QuotedStr(IntToStr(rgEmpresa.itemindex)) + ' Order by T.Empresa, T.Descl, C.Tdc, C.Doc'
    end;
  if rgTipoVenta.ItemIndex = 1 Then
    begin
        StrSql := 'Select T.empresa, C.TipoConsumo, C.Aux, T.Descl As Trabajador, Sum (C.TOT) As Total  ' +
                ' from ' +
                'tblConsumoC C ' +
                'Left Join tblTrabajador T on C.Aux = T.KOD ' +
                ' Where C.F_DOC Between ' + QuotedStr(FormatDateTime('DD/MM/YYYY', dtFechaIni.Date)) + ' and ' +
                QuotedStr(FormatDateTime('DD/MM/YYYY', dtFechaFin.Date)) + ' and TipoConsumo = ' + QuotedStr('C') +
                ' Order by T.Empresa, T.Descl, C.Tdc, C.Doc'
    end;
    qryConsumos.SQL.Clear;
    qryConsumos.sql.Add(StrSql);
    qryConsumos.Open;
end;

y ya esta funcionando normal

cosas del orinoco?

Al González 30-05-2011 07:28:39

Cita:

Empezado por oscarac (Mensaje 401796)
cosas del orinoco?

No, en programación casi siempre estas cosas se deben a algún descuido. :p


La franja horaria es GMT +2. Ahora son las 04:48:37.

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