Mejorar este codigo...

Mejorar este codigo...

Postby goosfancito » Fri Jan 26, 2024 10:52 am

Hola.
Pueden ayudarme a mejorar. este codigo? es para crear un procedimiento. pero no me gusta como ha quedado.
Code: Select all  Expand view
 BEGIN
      SET @cCampo  =  cCampo ;
      SET @cCadena  =  cCadena ;
      SET @cSelect =
      CONCAT( "
      select
      a.id AS c1,
      a.nombre as c2,
      a.habilitado as c3,
      b.id as c4,
      b.id_cliente as c5,
      b.telefono as c6
      FROM tbclientes AS a
      Left join tbdatos as b
      ON b.id_cliente = a.id
      ORDER BY a.nombre DESC "
,
      "WHERE ",
      @cCampo,
      " LIKE '%",
      @cCadena, "%'" ) ;
      PREPARE stmt FROM @cSelect ;
      execute stmt ;
      deallocate prepare stmt ;
   END
 
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: Mejorar este codigo...

Postby Antonio Linares » Fri Jan 26, 2024 4:52 pm

Gustavo,

Has probado a consultarlo con chatgpt ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Mejorar este codigo...

Postby goosfancito » Fri Jan 26, 2024 8:43 pm

no, voy a hacerlo.
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: Mejorar este codigo...

Postby goosfancito » Sat Jan 27, 2024 7:44 am

goosfancito wrote:no, voy a hacerlo.

Respuesta del GPT

Code: Select all  Expand view
BEGIN
    SET @cCampo = cCampo;
    SET @cCadena = cCadena;

    SET @cSelect = CONCAT("
        SELECT
            a.id AS c1,
            a.nombre AS c2,
            a.habilitado AS c3,
            b.id AS c4,
            b.id_cliente AS c5,
            b.telefono AS c6
        FROM tbclientes AS a
        LEFT JOIN tbdatos AS b ON b.id_cliente = a.id
        WHERE "
, @cCampo, " LIKE CONCAT('%', ?, '%')
        ORDER BY a.nombre DESC
    "
);

    PREPARE stmt FROM @cSelect;
    EXECUTE stmt USING @cCadena;
    DEALLOCATE PREPARE stmt;
END;
 
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 33 guests

cron