Reputation: 1
I have some directories saved like this in a table. The column is a varchar type and the strings are separated by /
'/Invoices/April/2012'
'/Expenses/2017/June/01'
'/Taxes/Company/'
How can I get a substring in order to get only
'/Invoices'
'/Expenses'
'/Taxes'
Upvotes: 0
Views: 330
Reputation: 1888
SELECT SUBSTRING(YourColumn, 0, CHARINDEX('/', YourColumn, 2))
FROM YourTable
Edit: Yes, CHARINDEX()
is 1-based, not 0-based. Yes, I hate it too.
Upvotes: 1