Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parameter is something or null

Status
Not open for further replies.

filipe29

Programmer
Jan 14, 2006
23
PT
hi i have the sql query :

select * from cliente
where nome like :pnome or :pnome is null

pnome is a parameter and when i go to the parameters strings i have 2 parameters not one,why??
 
don't you want it like this:
Code:
select * from cliente
where nome like :pnome or nome is null

with your exising query you're going to get, (assume parameter is LESPAUL):

Code:
SELECT * FROM cliente WHERE nome LIKE LesPaul or [b]LesPaul[/b] is null

you are also going to need to add the LIKE delimiter for your Database, either * (access JET SQL) or % (other SQL flavors)

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases: The Fundamentals of Relational Database Design
 
No what i want to do is to use sometimes the parameter and sometimes not.
 
how do you know if the user has entered a parameter? Do you have a Edit box on a form?

Code:
If EditBox.Text <> '' then
  SQL.ADD('SELECT * FROM Cliente WHERE nome LIKE ' + QuotedStr('%' + EditBox.Text + '%'))
else
  SQL.Add('SELECT * FROM Cliente');
SQL.Active := True;

Either way you'll need to add the LIKE delimiter. Have you tried this and leave the parameter blank? What does that return?

Code:
select * from cliente
where nome like :pnome

Leslie
 
i have a combo that selects the field and a textedit that set the text to find.In the combo i have fields of type string and integer and want to do a partial search.

So i need more than one parameter and when a field is selected by the combobox the others are set to null.

But for some reason when i set in the sql strings that the same parameter can be null it shows mw on the parameters two.
 
Parameters can not be used for column names. They can only be used for the text as you put it.

One way to solve this is to create the SQL statement each time. For example:
Code:
...
  SQLCommand := 'SELECT * FROM cliente ' +
                'WHERE nome LIKE ' + QuotedStr(Edit1.Text) +
                ' OR ' + ComboBox1.Text + ' IS NULL';
...

Andrew
Hampshire, UK
 
Once more i dont want to check if the combotext is null but the parameter.And the parameter is not the column name.
 
again, don't use parameters, build your SQL each time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top