Reputation: 113
I have a column with entries in the format xxxx200_xx or in some instances xxx200_x.
Is it possible to remove the 200_ and the subsequent characters so that the remaining string is the 4, 5 or 6 digits before the 200_?
Thanks.
Upvotes: 0
Views: 45
Reputation: 13655
Simply use LEFT
and CHARINDEX
like so:
SELECT LEFT(yourColumn, CHARINDEX('200_',yourColumn)-1);
So this:
SELECT LEFT('xxx200_xx', CHARINDEX('200_','xxx200_xx')-1);
Outputs this:
'xxx'
Upvotes: 2