Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to use 'like' and 'substr' together

Author  Topic 

chulz90
Starting Member

26 Posts

Posted - 2013-04-08 : 00:19:56
hello..

i've some trouble in my query. i just want to know the right one from this query below

i know the simple query is:
select * from rspi_do where do_number like '%RS%';


but i want to know how use like and substr ???

select * from rspi_do where do_number like '%substr(RS-DI-02-00002,1,2)%';
but teh result is nothing, i want to know where's the right one???

can i use like and substr together?????

thank's for helping

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-08 : 01:45:45
select * from rspi_do where do_number like '%'+substring(RS-DI-02-00002,1,2)+'%';
Go to Top of Page

chulz90
Starting Member

26 Posts

Posted - 2013-04-08 : 02:20:33
quote:
Originally posted by bandi

select * from rspi_do where do_number like '%'+substring(RS-DI-02-00002,1,2)+'%';




still error
T___T
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-08 : 02:29:34
which error? Is it error or incorrect result?
Go to Top of Page

chulz90
Starting Member

26 Posts

Posted - 2013-04-08 : 03:40:07
it says error syntax

but i've founded finally :D

select * from rspi_do where do_number1,2 like '%'||substr(RS-DI-02-00002,1,2)||'%';

thank's bandi for response
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-09 : 00:29:30
quote:
Originally posted by chulz90

it says error syntax

but i've founded finally :D

select * from rspi_do where do_number1,2 like '%'||substr(RS-DI-02-00002,1,2)||'%';

thank's bandi for response



I think you are working on Oracle/DB2... My solution is for SQL Server..
Thats why you got the error...

--
Chandu
Go to Top of Page
   

- Advertisement -