Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > SQL
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #2  
Antiguo 07-06-2019
Avatar de oscarac
[oscarac] oscarac is offline
Miembro Premium
 
Registrado: sep 2006
Ubicación: Lima - Perú
Posts: 2.015
Poder: 22
oscarac Va por buen camino
y que tal si en lugar de usar parametros lo solucionas armando una cadena

algo asi como:

Código Delphi [-]
cadena := '';

if Edit1.Text<>'' then Cadena := cadena + edit1.text
if Edit2.Text<>'' then Cadena := cadena + edit2.text
if Edit3.Text<>'' then Cadena := cadena + edit3.text
if Edit4.Text<>'' then Cadena := cadena + edit4.text
if Edit5.Text<>'' then Cadena := cadena + edit5.text
if Edit6.Text<>'' then Cadena := cadena + edit6.text
if Edit7.Text<>'' then Cadena := cadena + edit7.text
if Edit8.Text<>'' then Cadena := cadena + edit8.text


yo tengo una funcion que una cadena de caracteres la separa en comas, para que se pueda ejecutar el sql usando IN

Código Delphi [-]
Function _Digito(_String : string ; _Tipo :Integer) :String;
var _Dig :String; _i :Integer;
begin
  _Dig := '';
  if _tipo = 0 then
    begin
      For _i:= 1 to Length(_string) do
        _Dig := _Dig + Copy (_String, _i, 1) +  ',';
      Result := Copy (_Dig,1, Length(_DIG) -1);
    end
  Else
  begin
      For _i:= 1 to Length(_string) do
        _Dig := _Dig + QuotedStr(Copy (_String, _i, 1)) +  ',';
      Result := '(' + Copy (_Dig,1, Length(_DIG) -1) +')';

  end;
end;

si la ejecuto asi
_cad := _digito ('1234',1)

el resultado es ('1','2','3','4')


entonces en la consulta sql podria usar...

SELECT MARCA,CODIGO,FORMULA,NUMERO,DESCRI,CODIGOI FROM INVENTA WHERE M1 in _cad


yo lo hago mas o menos asi

Código Delphi [-]
_CadDB := _Digito('D1I+',1);
  _CadHB := _Digito('H2S-',1);
  While not qryPlanContable.Eof do
  Begin

    Strsql := 'select Left(M.cuenta, 2) As Cuenta, M.Libro, Lbr.Descripcion As DLibro, ';
    if rgMoneda.ItemIndex = 1 then
      Strsql := Strsql +  'SUM (Case when M.DH in ' + _CadDB + ' then M.u_IMP else 0.00 End) AS DEBE, ' +
                          'SUM (Case when M.DH in ' + _CadHB + ' then M.u_IMP else 0.00 End) AS HABER, ' +
                          'SUM (Case when M.DH in ' + _CadDB + ' then M.n_IMP else 0.00 End) AS DEBEMN, ' +
                          'SUM (Case when M.DH in ' + _CadHB + ' then M.n_IMP else 0.00 End) AS HABERMN, ' +
                          'SUM (Case when M.DH in ' + _CadDB + ' then M.u_IMP else 0.00 End) AS DEBEME, ' +
                          'SUM (Case when M.DH in ' + _CadHB + ' then M.u_IMP else 0.00 End) AS HABERME '
    Else
      Strsql := Strsql +  'SUM (Case when M.DH in ' + _CadDB + ' then M.n_IMP else 0.00 End) AS DEBE, ' +
                          'SUM (Case when M.DH in ' + _CadHB + ' then M.n_IMP else 0.00 End) AS HABER, ' +
                          'SUM (Case when M.DH in ' + _CadDB + ' then M.n_IMP else 0.00 End) AS DEBEMN, ' +
                          'SUM (Case when M.DH in ' + _CadHB + ' then M.n_IMP else 0.00 End) AS HABERMN, ' +
                          'SUM (Case when M.DH in ' + _CadDB + ' then M.u_IMP else 0.00 End) AS DEBEME, ' +
                          'SUM (Case when M.DH in ' + _CadHB + ' then M.u_IMP else 0.00 End) AS HABERME ';
    Strsql := Strsql +  'from (tblmovimientocontable M with (nolock) ' +
              ' Left Join TblLibro Lbr with (nolock) ON (Lbr.Empresa = M.Empresa and Lbr.KOD = M.Libro)) '  +
              ' where M.Empresa = ' + QuotedStr(dmGlobal.g_CodigoEmpresa) + ' and M.Periodo = ' + QuotedStr(dmGlobal.g_Periodo) +
              ' and Left (M.cuenta,2) = '+ QuotedStr(qryPlanContableCuenta.AsString) +
              ' Group by Left(M.CUENTA,2), M.Libro, Lbr.Descripcion  ' +
              'order by Left(M.CUENTA,2), M.Libro';



quiza eso pueda ayudarte
__________________
Dulce Regalo que Satanas manda para mi.....
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
Consulta Anidada farrop SQL 1 04-07-2006 19:28:06
Consulta anidada Malon SQL 5 07-05-2004 17:58:45
Consulta anidada fjcg02 SQL 6 05-02-2004 08:47:58
consulta anidada pzala SQL 2 14-12-2003 22:43:16
consulta sql anidada davidgaldo SQL 2 13-11-2003 14:42:00


La franja horaria es GMT +2. Ahora son las 14:06:38.


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