Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Everything Right of character in string 1

Status
Not open for further replies.

RJL1

Technical User
Oct 3, 2002
228
US
I have a need to return everything to the right of an = sign in a string.

I been trying to use this but keep getting and error.

Code:
SELECT
RIGHT(I.MESSAGETRACKEDDATA, CHARINDEX('=', REVERSE(I.MESSAGETRACKEDDATA),-1))
FROM
INBOUNDX12MESSAGELOG I
WHERE
CONVERT (VARCHAR(30),I.RECEIVETIME,101) = CONVERT (VARCHAR(30),GETDATE(),101)

The field that hold the date is type = text.

My string looks like

Code:
Header-W05-Depositor Order Number=0822042930

And I like to get everything right of the = sign.

Code:
0822042930

The problem is thta the portion left of the equal sign can vary in lenght depnding on customer.

Thanks for any help


 
How about:

Code:
DECLARE @somestring VARCHAr(50)
SET @somestring = 'Header-W05-Depositor Order Number=0822042930'

SELECT RTRIM(LTRIM(SUBSTRING(@somestring, CHARINDEX('=', @somestring) + 1, 1000)))

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
C#.NET Programmer
 
Worked like a charm

Thanks
 
Just be aware that if there is no = sign in the data, you will get the entire data, not an empty string. There are times when this is ok.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top