Reputation: 1095
In MS-SQL 2008 I have a varchar field that holds data. It will have names like this:
I need the data to read in my output like this (so gathering the first name listed only if there are multiple separated by a slash):
I am assuming this needs to be some type of function but not sure. Appreciate the help, thank you.
Upvotes: 0
Views: 74
Reputation: 1270001
SQL Server doesn't have very good string manipulation functions, but this isn't so hard:
select (case when names like '%/%'
then left(names, charindex('/', names) - 1)
else names
end)
EDIT:
Mikael's suggestion saves the case
statement:
select left(names + '/', charindex('/', names) - 1)
Upvotes: 2