Thread View: borland.public.interbase.sql
4 messages
4 total messages
Started by Cara
Thu, 19 Dec 2002 16:06
SQL, (Like) as Param?
Author: Cara
Date: Thu, 19 Dec 2002 16:06
Date: Thu, 19 Dec 2002 16:06
14 lines
1450 bytes
1450 bytes
Does anyone know the correct syntax for using 'Like %' in an SQL statment and passing it a parameter? I am using the SQLAPI to connect to the database.
Query="SELECT LastName,Firstname,employeeNbr FROM Employee where LastName LIKE :NM)";
rsP.setCommandText(Query);
rsP.Param("NM").setAsString() = txtName->Text.c_str();
rsP.Execute();
The Query works fine if I hardcode the Parameter:
Query="SELECT LastName,Firstname,employeeNbr FROM Employee where LastName LIKE 'ABC%')";
But it flops no matter how I rearrange the Parameter and the %.???
Thanks,
Cara
Re: SQL, (Like) as Param?
Author: Brian
Date: Thu, 19 Dec 2002 16:28
Date: Thu, 19 Dec 2002 16:28
24 lines
1759 bytes
1759 bytes
"Cara" <cbrookins@littlerock.state.ar.us> wrote:
>
>Does anyone know the correct syntax for using 'Like %' in an SQL statment and passing it a parameter? I am using the SQLAPI to connect to the database.
>
>Query="SELECT LastName,Firstname,employeeNbr FROM Employee where LastName LIKE :NM)";
>rsP.setCommandText(Query);
>rsP.Param("NM").setAsString() = txtName->Text.c_str();
>rsP.Execute();
>
>The Query works fine if I hardcode the Parameter:
>Query="SELECT LastName,Firstname,employeeNbr FROM Employee where LastName LIKE 'ABC%')";
>But it flops no matter how I rearrange the Parameter and the %.???
>
>Thanks,
>Cara
>
Try "...... Like " + <V> + ")"
where <V> is your string variable and the '+' are used to
concatenate.
Brian
Re: SQL, (Like) as Param?
Author: Wayne Niddery [TeamB]
Date: Thu, 19 Dec 2002 21:07
Date: Thu, 19 Dec 2002 21:07
16 lines
1528 bytes
1528 bytes
"Brian" <brianellul@ecenglish.com> wrote in message news:3e01f3b3$1@newsgroups.borland.com... > > Try "...... Like " + <V> + ")" > > where <V> is your string variable and the '+' are used to > concatenate. Not the problem, parameters take care of quoting for you. -- Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com) RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html "The only reason some people get lost in thought is because it's unfamiliar territory." - Paul Fix
Re: SQL, (Like) as Param?
Author: Wayne Niddery [TeamB]
Date: Thu, 19 Dec 2002 21:10
Date: Thu, 19 Dec 2002 21:10
24 lines
1934 bytes
1934 bytes
"Cara" <cbrookins@littlerock.state.ar.us> wrote in message
news:3e01ee6f$1@newsgroups.borland.com...
>
> Query="SELECT LastName,Firstname,employeeNbr FROM Employee where LastName
LIKE :NM)";
> rsP.setCommandText(Query);
> rsP.Param("NM").setAsString() = txtName->Text.c_str();
> rsP.Execute();
>
> The Query works fine if I hardcode the Parameter:
> Query="SELECT LastName,Firstname,employeeNbr FROM Employee where LastName
LIKE 'ABC%')";
> But it flops no matter how I rearrange the Parameter and the %.???
It fails because you still need to include the wildcard somewhere. You can
either put it in the query statement or concatenate it to your string value
before assigning it to the parameter.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html
"The only reason some people get lost in thought is because it's unfamiliar
territory." - Paul Fix
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads