user6308605
user6308605

Reputation: 731

select statement using substring as WHERE condition

How do i Select * from tableA where the condition is like this :

TableA:

|**Col A**  | **Col B** |
| Hello| 9*9 |
| World| 2*2 |
| Cat | 11*11 |

WHERE Col B contains same Number like '9*9'.

Col B is varchar (100).

I was thinking MAYBE using subString as the condition like :

Substring (1) = SubString (3)... but it didnt work out. Any other solution?

Upvotes: 0

Views: 67

Answers (2)

ysth
ysth

Reputation: 98423

Check that the string is equal to its first part plus a '*' plus its first part again:

colb = concat(left(colb,length(colb)/2-1),'*',left(colb,length(colb)/2-1))

Upvotes: 0

beejm
beejm

Reputation: 2481

select * from tableA
WHERE left(col_b, charindex('*', col_b) - 1) = right(col_b, len(col_b) - charindex('*', col_b))

I think this is what you need left, right and charindex

Upvotes: 1

Related Questions