SQL.Add(' where ' + ' (upper(ACMSUB.clientes COLLATE ES_ES_CI_AI )) LIKE ' +quotedstr('%' + edcliente.Text + '%')+'');
quitando los collates y demas chequea la ultima parte, asi me funciona a mi en mi programa
Escrito 17 marzo 2010 - 08:17
SQL.Add(' where ' + ' (upper(ACMSUB.clientes COLLATE ES_ES_CI_AI )) LIKE ' +quotedstr('%' + edcliente.Text + '%')+'');
Escrito 17 marzo 2010 - 09:22
Bueno, por algo yo dije que quizá lo que decía era una tontería... sabiendo que eso es una de las primeras cosas que se chequean... pero también puede existir la posibilidad de que nos olvidemos.
No era mi intención ofenderte ni molestar.
Estoy pensando que otra alternativa se podría probar...
Saludos,
Escrito 17 marzo 2010 - 09:30
¿ Ya intentaste con parametros ?
Salud OS
Escrito 17 marzo 2010 - 09:33
...pero no puedo resolver UN CONDENADO LIKE EN UN TEXTO...![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
¿No hablarás de un campo tipo TEXT? ¿no?![]()
Escrito 17 marzo 2010 - 09:35
¿ Ya intentaste con parametros ?
Salud OS
Sí, Eliseo. De hecho, el código original de ayer era exclusivamente con parámetros..., ¿y qué crees? Que no funcionó..., por eso me puse a hacer el proceso con el valor directo.
Escrito 17 marzo 2010 - 09:35
Pues he probado mi teoría de parámetros tanto en IBExpert como en Delphi y funciona como lo soñe
![]()
Salud OS
Escrito 17 marzo 2010 - 09:38
¿ Ya intentaste con parametros ?
Salud OS
Sí, Eliseo. De hecho, el código original de ayer era exclusivamente con parámetros..., ¿y qué crees? Que no funcionó..., por eso me puse a hacer el proceso con el valor directo.
Me parece que no tienes problema con la sentencia LIKE, tienes el probema en otro lado, tal vez en el componente que estás usando, ¿ ya viste las imagenes que he subido ?
Salud OS
Escrito 17 marzo 2010 - 09:47
¿ Ya intentaste con parametros ?
Salud OS
Sí, Eliseo. De hecho, el código original de ayer era exclusivamente con parámetros..., ¿y qué crees? Que no funcionó..., por eso me puse a hacer el proceso con el valor directo.
Me parece que no tienes problema con la sentencia LIKE, tienes el probema en otro lado, tal vez en el componente que estás usando, ¿ ya viste las imagenes que he subido ?
Salud OS
ADOQuery's..., pero hasta el momento, han funcionado de perlas. El problema es que la falta de presupuesto no permite usar otra cosa. Sobre todo, por que el HHH Gobierno del Distrito Federal quiere usar MS SQL Server y no otra cosa menos compleja de manejar...
Y sí, ya ví las imágenes. Voy a probar mañana a primerísima hora.
Saludines.
Escrito 17 marzo 2010 - 09:52
Por cierto, ¿alguien está viendo el soccer?
Escrito 17 marzo 2010 - 09:59
Por cierto, ¿alguien está viendo el soccer?
¿ Quien juega ?
Salud OS
Escrito 17 marzo 2010 - 10:03
Pues juega México vs Corea del Norte.
Y si, lo estoy medio viendo jejejejeje, van 0-0
Saludos
KAfastoforman
Escrito 18 marzo 2010 - 06:27
Les platico. Por motivos de una consulta general, se me ocurrió utilizar la sentencia LIKE en mi conjunto de sentencias SQL, por medio de éste código...
delphi
procedure TfrmBsqdDts.bitbttnBscrClick(Sender: TObject); var wsSQLTxt : widestring; sArmr : string; begin wsSQLTxt := 'SELECT Ca_Area, Ca_Titulo, Ca_Nombre, Ca_Paterno, Ca_Materno, '+ 'Ca_institucion, Ca_Dirg, Ca_Dir, Ca_Sub, Ca_Jud FROM carea'+ ' WHERE (ca_cancelado = 0) '; if (edtArea.Text <> '') OR (edtTitulo.Text <> '') OR (edtNombres.Text <> '') OR (edtAplldPaterno.Text <> '') OR (edtAplldMaterno.Text <> '') then begin if (edtArea.Text <> '') then begin sArmr := '%'+edtArea.Text+'%'; wsSQLTxt := wsSQLTxt + 'AND (ca_area LIKE '+sArmr+')'; end; if (edtTitulo.Text <> '') then wsSQLTxt := wsSQLTxt + 'AND (ca_titulo LIKE '+QuotedStr('%'+edtTitulo.Text+'%')+') '; if (edtNombres.Text <> '') then wsSQLTxt := wsSQLTxt + 'AND (ca_nombre LIKE '+QuotedStr('%'+edtNombres.Text+'%')+') '; if (edtAplldPaterno.Text <> '') then wsSQLTxt := wsSQLTxt + 'AND (ca_paterno LIKE '+QuotedStr('%'+edtAplldPaterno.Text+'%')+') '; if (edtAplldMaterno.Text <> '') then wsSQLTxt := wsSQLTxt + 'AND (ca_materno LIKE '+QuotedStr('%'+edtAplldMaterno.Text+'%')+') '; end; wsSQLTxt := wsSQLTxt +';'; with dtamdlDts.ADOQryBsqd do begin Active := False; SQL.Clear; SQL.Text := wsSQLTxt; Active := True; end; end;
Arrojándome éste valor para la variable wsSQLTxt:
sql
SELECT Ca_Area, Ca_Titulo, Ca_Nombre, Ca_Paterno, Ca_Materno, Ca_institucion, Ca_Dirg, Ca_Dir, Ca_Sub, Ca_Jud FROM carea WHERE (ca_cancelado = 0) AND (ca_area LIKE %APOYO%);
El problema esencial es que me envía éste error desde el SQLServer:
Project AreaTree.exe raised exception class EOleException with message '[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'APOYO'.
Y obviamente no ejecuta ni me muestra los datos que se requieren.
En mi confiabilísimo manejador de SQL Server, detecté parte del problema, que consiste en la inexistencia de dos comillas simples junto a los signos de porcentaje, y SQL Server acepta una sintaxis así:
sql
SELECT Ca_Area, Ca_Titulo, Ca_Nombre, Ca_Paterno, Ca_Materno, Ca_institucion, Ca_Dirg, Ca_Dir, Ca_Sub, Ca_Jud FROM carea WHERE (ca_cancelado = 0) AND (ca_area LIKE '%APOYO%');
Mi pregunta va en el sentido, ¿cómo puedo asegurarme que solamente UNA comilla simple será añadida a mi texto? He usado QuotedStr() y juegos de comillas dentro del código, pero me pone DOS comillas simples y obviamente ésto genera un error dentro del motor de base de datos...
¿Algún consejo o solución que puedan aportarme, por favor?
procedure TfrmBsqdDts.bitbttnBscrClick(Sender: TObject); var wsSQLTxt : widestring; begin wsSQLTxt := 'SELECT Ca_Area, Ca_Titulo, Ca_Nombre, Ca_Paterno, Ca_Materno, '+ 'Ca_institucion, Ca_Dirg, Ca_Dir, Ca_Sub, Ca_Jud FROM carea'+ ' WHERE (ca_cancelado = 0) '; begin if (edtArea.Text <> '') then begin // sArmr := '%'+edtArea.Text+'%'; wsSQLTxt := wsSQLTxt + ' AND (ca_area LIKE '+QuotedStr('%'+Edtarea.Text+'%')+' end else if (edtTitulo.Text <> '') then wsSQLTxt := wsSQLTxt + ' AND (ca_titulo LIKE '+QuotedStr('%'+edtTitulo.Text+'%')+' else if (edtNombres.Text <> '') then wsSQLTxt := wsSQLTxt + ' AND (ca_nombre LIKE '+QuotedStr('%'+edtNombres.Text+'%')+' else if (edtAplldPaterno.Text <> '') then wsSQLTxt := wsSQLTxt + ' AND (ca_paterno LIKE '+QuotedStr('%'+edtAplldPaterno.Text+'%')+' else if (edtAplldMaterno.Text <> '') then wsSQLTxt := wsSQLTxt +' AND (ca_materno LIKE '+QuotedStr('%'+edtAplldMaterno.Text+'%')+' ; end; with dtamdlDts.ADOQryBsqd do begin Active := False; SQL.Clear; SQL.add(wsSQLtxt); sql.open; end; end;
Escrito 18 marzo 2010 - 05:47
Escrito 24 marzo 2010 - 11:33
Pues he hecho la prueba con una base de datos MS SQL Server y ADO y me funciono de perlas. Te dejo la imagen para que veas.
Salud OS
procedure TfrmBsqdDts.bitbttnBscrClick(Sender: TObject); var wsSQLTxt : widestring; begin wsSQLTxt := 'SELECT Ca_Area, Ca_Titulo, Ca_Nombre, Ca_Paterno, Ca_Materno, '+ 'Ca_institucion, Ca_Dirg, Ca_Dir, Ca_Sub, Ca_Jud FROM carea'+ ' WHERE (ca_cancelado = 0) '; if (edtArea.Text <> '') OR (edtTitulo.Text <> '') OR (edtNombres.Text <> '') OR (edtAplldPaterno.Text <> '') OR (edtAplldMaterno.Text <> '') then begin if (edtArea.Text <> '') then begin dtamdlDts.ADOQryBsqd.Parameters.ParamByName('pArea').Value := '%'+edtArea.Text+'%'; wsSQLTxt := wsSQLTxt + 'AND (ca_area LIKE :pArea)'; end; if (edtTitulo.Text <> '') then begin dtamdlDts.ADOQryBsqd.Parameters.ParamByName('pTitulo').Value := '%'+edtTitulo.Text+'%'; wsSQLTxt := wsSQLTxt + 'AND (ca_titulo LIKE :pTitulo) '; end; if (edtNombres.Text <> '') then begin dtamdlDts.ADOQryBsqd.Parameters.ParamByName('pNombre').Value := '%'+edtNombres.Text+'%'; wsSQLTxt := wsSQLTxt + 'AND (ca_nombre LIKE :pNombre) '; end; if (edtAplldPaterno.Text <> '') then begin dtamdlDts.ADOQryBsqd.Parameters.ParamByName('pApPaterno').Value := '%'+edtAplldPaterno.Text+'%'; wsSQLTxt := wsSQLTxt + 'AND (ca_paterno LIKE :pApPaterno) '; end; if (edtAplldMaterno.Text <> '') then begin dtamdlDts.ADOQryBsqd.Parameters.ParamByName('pApMaterno').Value := '%'+edtAplldMaterno.Text+'%'; wsSQLTxt := wsSQLTxt + 'AND (ca_materno LIKE :pApMaterno) '; end; end; wsSQLTxt := wsSQLTxt +';'; with dtamdlDts.ADOQryBsqd do begin Close; SQL.Clear; SQL.Text := wsSQLTxt; Open; end; end;
Escrito 24 marzo 2010 - 12:14
Escrito 24 marzo 2010 - 12:42
CREATE PROCEDURE dbo.SePareceA @PArea VARCHAR(255) = NULL, @PTitulo VARCHAR(255) = NULL, @PNombre VARCHAR(255) = NULL, @PAPaterno VARCHAR(255) = NULL, @PAMaterno VARCHAR(255) = NULL AS BEGIN SELECT Ca_Area, Ca_Titulo, Ca_Nombre, Ca_Paterno, Ca_Materno, Ca_institucion, Ca_Dirg, Ca_Dir, Ca_Sub, Ca_Jud FROM carea WHERE ca_cancelado = 0 AND (@PArea IS NULL OR ca_area LIKE '%' + @PArea + '%') AND (@PTitulo IS NULL OR ca_titulo LIKE '%' + @PtITULO + '%') AND (@Pnombre IS NULL OR ca_nombre LIKE '%'+ @PNombre+'%' ) AND (@PAPaterno IS NULL OR ca_paterno LIKE '%'+ @PAPaterno +'%') AND (@PAMaterno IS NULL OR ca_materno LIKE '%' + @PAMaterno + '%') END
procedure TfrmBsqdDts.bitbttnBscrClick(Sender: TObject); begin if (edtArea.Text <> '') OR (edtTitulo.Text <> '') OR (edtNombres.Text <> '') OR (edtAplldPaterno.Text <> '') OR (edtAplldMaterno.Text <> '') then with dtamdlDts.ADOStoredProc do begin Close; if (edtArea.Text <> '') then Parameters.ParamByName('@PArea').Value := edtArea.Text else Parameters.ParamByName('@PArea').Value := null; if (edtTitulo.Text <> '') then Parameters.ParamByName('@PTitulo').Value := edtTitulo.Text else Parameters.ParamByName('@PTitulo').Value:= null; . . . Open; end; end;
Escrito 24 marzo 2010 - 12:58
Hola TiammatMX, me extraña el hecho de que primero referencias al parámetro y luego agregas a la cadena parte de la instrucción SQL.
Creo que debería ser al revés...
...Al menos con los componentes que emplean las parámetros TParam el proceso es así: Primeramente se elabora la consulta y mediante un método denominado ParseSQL es que se recién se crean los parámetros. Luego es posible las asignaciones.
No recuerdo como es el caso de ADO y su TParameter pero si sigue la misma filosofía es primero el SQL y luego las asignaciones.
Escrito 24 marzo 2010 - 12:59
Que tal tiammatmx, pues yo te recomiendo que crees un storedproc en la base de datos de la siguiente manera:
sql
CREATE PROCEDURE dbo.SePareceA @PArea VARCHAR(255) = NULL, @PTitulo VARCHAR(255) = NULL, @PNombre VARCHAR(255) = NULL, @PAPaterno VARCHAR(255) = NULL, @PAMaterno VARCHAR(255) = NULL AS BEGIN SELECT Ca_Area, Ca_Titulo, Ca_Nombre, Ca_Paterno, Ca_Materno, Ca_institucion, Ca_Dirg, Ca_Dir, Ca_Sub, Ca_Jud FROM carea WHERE ca_cancelado = 0 AND (@PArea IS NULL OR ca_area LIKE '%' + @PArea + '%') AND (@PTitulo IS NULL OR ca_titulo LIKE '%' + @PtITULO + '%') AND (@Pnombre IS NULL OR ca_nombre LIKE '%'+ @PNombre+'%' ) AND (@PAPaterno IS NULL OR ca_paterno LIKE '%'+ @PAPaterno +'%') AND (@PAMaterno IS NULL OR ca_materno LIKE '%' + @PAMaterno + '%') END
Despues de eso, lo conectas con un TADOStoredProc, y entonces tu comparación seria la siguiente:
delphi
procedure TfrmBsqdDts.bitbttnBscrClick(Sender: TObject); begin if (edtArea.Text <> '') OR (edtTitulo.Text <> '') OR (edtNombres.Text <> '') OR (edtAplldPaterno.Text <> '') OR (edtAplldMaterno.Text <> '') then with dtamdlDts.ADOStoredProc do begin Close; if (edtArea.Text <> '') then Parameters.ParamByName('@PArea').Value := edtArea.Text else Parameters.ParamByName('@PArea').Value := null; if (edtTitulo.Text <> '') then Parameters.ParamByName('@PTitulo').Value := edtTitulo.Text else Parameters.ParamByName('@PTitulo').Value:= null; . . . Open; end; end;
ya solo tendrias que terminar la asignaciónd e parametros y se supone tendria que funcionarte, si eso no funciona, entonces si, que se arme la balacera jajajaja.
Saludos
Kafastoforman
PD si no te funciona "is null" en SQL lo puedes cambialo a "= null"
Escrito 26 marzo 2010 - 12:29
Escrito 26 marzo 2010 - 12:38