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!

search just a few caracters

Status
Not open for further replies.

filipe29

Programmer
Jan 14, 2006
23
PT
Hi.How to do with a integer field what i do like strings

select * from venda
where nome like '%'+xxxxx+'%'

nome is a string and i want to do the same with a integer field
 
Code:
select * from venda
where cast(integerColumn as varchar(20)) like '%'+xxxxx+'%'
 
i have now:
select * from cliente
where cast(idcliente as varchar(20)) like '%'+61+'%'

and i receive:

Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value '%' to a column of data type int.
 
select * from cliente
where cast(idcliente as varchar(20)) like '%61%'

or

select * from cliente
where cast(idcliente as varchar(20)) like '%'+convert(varchar,61)+'%'

If the idcliente is already a varchar then this is all you need

select * from venda
where nome like '%'+convert(varchar,61)+'%'


Denis The SQL Menace
SQL blog:
Personal Blog:
 
yes.I did it but now i need to do that by a parameter on runtime.
 
Sorry i forgot to mention that when i talk in runtime i must say that i am developing on delphi.
 
if idcliente is numeric, and if you go ahead with the LIKE strategy, then you will return idcliente=610, idcliente=161, idcliente=61937, etc.

are you sure you want to do that?

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top