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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 substring

Author  Topic 

kt
Yak Posting Veteran

88 Posts

Posted - 2014-11-04 : 15:19:07
I have the table with this format
Q09
Qv9
WC8
KT78
QH2
QB2
UO0

I want the query to get only the values that start with Q and third characters are in 9 and 2, so the results will show below
Q09
Qv9
QH2
QB2

select * from tbl
where vOrder like 'Q%' and (SUBSTRING(LTRIM(vOrder ),1,3) in ('3')) and (SUBSTRING(LTRIM(vOrder ),1,3) in ('5'))

Can anyone plz help?

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-04 : 16:01:39
Select * from tbl
where vOrder like 'Q_9' or vOrder like 'Q_2'


basically, ignore the second character.
Go to Top of Page

kt
Yak Posting Veteran

88 Posts

Posted - 2014-11-04 : 16:06:15
Thank you
Go to Top of Page
   

- Advertisement -