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!

wrong sintax 1

Status
Not open for further replies.

filipe29

Programmer
Jan 14, 2006
23
PT
what's wrong with this syntax?

select * from cliente
where nome like =:p1 or like =:p2 is null
 
I assume :p1 and :p2 are oracle variables?


declare @p1 varchar (10) @p2 varchar (10)
select @p1 = '%a%', @p2 ='%b%'


select * from cliente
where nome like @p1
or nome like '@p2'
or nome is null

what are you trying to accomplish with this query?


Denis The SQL Menace
SQL blog:
Personal Blog:
 
Remove last "like".

And what the frell is =:p1 ?

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
SQL Denis - does '@p2' substitute, or do you mean:
Code:
declare @p2 varchar(10)
select @p2 = 'b'

select
...
and nome like '%' + :p2 + '%'
?
 
Substitutes

declare @p1 varchar (10) @p2 varchar (10)
select @p1 = '%a%', @p2 ='%b%'


select * from cliente
where nome like @p1
or nome like '@p2'
or nome is null

or

declare @p1 varchar (10) @p2 varchar (10)
select @p1 = 'a', @p2 ='b'


select * from cliente
where nome like '%' + @p1 + '%'
or nome like '%' + @p2' + '%'
or nome is null

I just find it easier to do it at the variable level

Denis The SQL Menace
SQL blog:
Personal Blog:
 
That's interesting. If you want to use 'like' to search for an @, do you have to escape it somehow?
 
sorry i forgot to mention that p1 is a parameter
 
Yes, I see that; but how does
Code:
select * from cliente
where nome like @p1 
or nome like '@p2'
or nome is null
'know' that you mean the content of the variable p2, not the string '@p2'?
 
filipe29,

here is an example against that you can run in pubs

use pubs

declare @p1 varchar (10) ,@p2 varchar (10)
select @p1 = '%a%', @p2 ='%b%'

select au_lname,au_fname,phone from authors
where au_lname like @p1
or au_lname like @p2
or au_lname is null

Denis The SQL Menace
SQL blog:
Personal Blog:
 
Oh, rats - I thought that MS must have enhanced SQL Server to be more like PHP. And I was going to give you a star. Still, you might be interested in a virtual display cabinet that I have for sale, to hold all your other ones.
 
Congratulations, Denis for being voted tip master of the week.

That alone should cheer you up on a miserably cold day.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Hi again.i think that in adoquery the null function doesnt seems to work.(sql server 2000)

Now i have :

select "bla bla bla"
where nome like :param1 or :param1 is null

and nothing happens when param1 is null
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top