0

I have a varchar variable been defined like this.

declare @IDs varchar(50)
set  @IDs ='111,123,567,'

Now I need to extract the last value in the list always 567.

The values in @IDs can be like this also

set  @IDs ='56,'

In this case we need extract only the value 56.

How can we do it?

1

2 Answers 2

1

i think you will find this user defined function to split the string helpful:

http://www.codeproject.com/Articles/7938/SQL-User-Defined-Function-to-Parse-a-Delimited-Str

Sign up to request clarification or add additional context in comments.

Comments

0

You can use the string splitter found here: http://www.sqlservercentral.com/articles/Tally+Table/72993/

It is very fast, you can call it like so:

SELECT *
FROM dbo.DelimitedSplit8K(@IDs,',')

This will return you a result set of all the values in the string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.