troubleshooting Question

Need help with CHARINDEX...

Avatar of Bobby X
Bobby XFlag for United States of America asked on
Microsoft SQL Server 2005
4 Comments4 Solutions334 ViewsLast Modified:

I have a query that returns the following columns:

Col1 (varchar)
Col2 (varchar)
Col3 (int)

Col1 contains a comma-delimited list of values, e.g., "27664,34874,43409,49887".

How do I extract and return the value of the first item from the list (Col1)? For example, 27664.
NOTE: Not all rows return a list of values in Col3. In other words, certain rows may return only one value, e.g., 12345; some may return NULL. I've tried to use a combination of CHARINDEX searching for "," and SUBSTRING() but have been getting an error.

Please provide SQL statement.

Thanks a lot.
Join our community to see this answer!
Unlock 4 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 4 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros