Skip to content
Advertisement

SQL Select Value From Comma Delimited List

I have a field in my database called “Notes”. It contains a comma delimited list of values.

I want to perform a SELECT Query that only returns the first value in the “Notes” field.

This query would also return additional fields from the database.

for example

Is this possible, and how do I do it?

Advertisement

Answer

You can use CHARINDEX with SUBSTRING:

Demo

Result

|      first_value |
--------------------
| comma after this |

As mentioned in the comments, you should normalize your structure and not have more than one value stored in a single attribute.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement