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.
| Author |
Topic |
|
shahid09
Starting Member
35 Posts |
Posted - 2008-07-02 : 09:51:17
|
| Hi All,I am running SQL query. I want to get all Contract IDS from the table where second last digit is 5. Any suggestion how can i use regex here ?Our contract ID is in this format.R51001550R23434567R12489750R23456560Thanks,Shahid |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-02 : 09:53:50
|
| One of the methodswhere col like '%5[0-9]'MadhivananFailing to plan is Planning to fail |
 |
|
|
shahid09
Starting Member
35 Posts |
Posted - 2008-07-02 : 10:06:14
|
| Hi madhivanan,Thanks for the reply. I am getting following error."The data types of the operands for the operation" are not compatible.Thanksi used this codeSELECT CONTRACT_ID FROM Table_cont WHERE CONTRACT_ID = '%5[0-9]' |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-02 : 10:11:29
|
| Madhi's example said LIKE not =i.e...WHERE CONTRACT_ID LIKE '%5[0-9]'Em |
 |
|
|
shahid09
Starting Member
35 Posts |
Posted - 2008-07-02 : 10:19:40
|
| Thanks Now throwing following error"A LIKE predicate or POSSTR scalar function is not valid because the first operand is not a string expression or the second operant is not a string'SELECT CONTRACT_ID FROM Table_cont WHERE CONTRACT_ID Like '%5[0-9]'Thanks |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-07-02 : 10:22:03
|
| SELECT CONTRACT_ID FROM Table_cont WHERE SUBSTRING(CONTRACT_ID,8,1) = '5'If contract is always 9 charactersSELECT CONTRACT_ID FROM Table_cont WHERE SUBSTRING(REVERSE(CONTRACT_ID),2,1) = '5'if it is notJim |
 |
|
|
|
|
|