Jan 14, 2006 #1 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
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
Jan 14, 2006 #2 swampBoogie Programmer Jan 6, 2003 1,660 SE Code: select * from venda where cast(integerColumn as varchar(20)) like '%'+xxxxx+'%' Upvote 0 Downvote
Jan 14, 2006 Thread starter #3 filipe29 Programmer Jan 14, 2006 23 PT 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. Upvote 0 Downvote
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.
Jan 14, 2006 #4 SQLDenis Programmer Oct 1, 2005 5,575 US 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:http://sqlservercode.blogspot.com/ Personal Blog:http://otherthingsnow.blogspot.com/ Upvote 0 Downvote
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:http://sqlservercode.blogspot.com/ Personal Blog:http://otherthingsnow.blogspot.com/
Jan 14, 2006 Thread starter #5 filipe29 Programmer Jan 14, 2006 23 PT yes.I did it but now i need to do that by a parameter on runtime. Upvote 0 Downvote
Jan 14, 2006 #6 SQLDenis Programmer Oct 1, 2005 5,575 US replace 61 with @var example declare @v int -- or make varchar and take out convert in the where clause select @v =61 select * from venda where nome like '%'+convert(varchar,@v)+'%' Denis The SQL Menace SQL blog:http://sqlservercode.blogspot.com/ Personal Blog:http://otherthingsnow.blogspot.com/ Upvote 0 Downvote
replace 61 with @var example declare @v int -- or make varchar and take out convert in the where clause select @v =61 select * from venda where nome like '%'+convert(varchar,@v)+'%' Denis The SQL Menace SQL blog:http://sqlservercode.blogspot.com/ Personal Blog:http://otherthingsnow.blogspot.com/
Jan 14, 2006 Thread starter #7 filipe29 Programmer Jan 14, 2006 23 PT Sorry i forgot to mention that when i talk in runtime i must say that i am developing on delphi. Upvote 0 Downvote
Jan 14, 2006 #8 r937 Technical User Jun 30, 2002 8,847 CA 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 Upvote 0 Downvote
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
Jan 14, 2006 #9 SQLDenis Programmer Oct 1, 2005 5,575 US make a stored procedure out of it and then it doesn't matter if you use Deplhi, Kylix or Fujitsu COBOL Denis The SQL Menace SQL blog:http://sqlservercode.blogspot.com/ Personal Blog:http://otherthingsnow.blogspot.com/ Upvote 0 Downvote
make a stored procedure out of it and then it doesn't matter if you use Deplhi, Kylix or Fujitsu COBOL Denis The SQL Menace SQL blog:http://sqlservercode.blogspot.com/ Personal Blog:http://otherthingsnow.blogspot.com/