1

I have this string on one of the columns on my database table

black lines^TECH43223

I need to split the string, and this is my code to split the string

Select LTRIM(SUBSTRING(Complaint, CHARINDEX('^',Complaint)+1, len(Complaint))) from       Service

and the result is

TECH43223

But what I need is that string "black lines". Can I split the string, and get the first value?

1 Answer 1

1

You're so close!! The SUBSTRING() function works as follows:

SUBSTRING( Value, Start Position, Length)

Start from the beginning of the string, and trim at the occurrence of the character:

SELECT LTRIM(SUBSTRING(Complaint, 1, CHARINDEX('^',Complaint) ) from Service

Test it, if the result includes your split character ^ you may need to subtract 1:

SELECT LTRIM(SUBSTRING(Complaint, 1, CHARINDEX('^',Complaint)-1 ) from Service

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

2 Comments

ah you got it, i'll remove mine.
@set Thanks bro ! you're a genius, haha . i'm already creating my function for this problem, then you came . thank you so much !

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.