March 14, 2016 at 6:12 am
Hi All,
I have a string like below
DWDate,Email,UserID,ID,LoanNum,PersonEmail,LoanDate,Paymt
I want to get the last one that is Paymt. Actually the upper section is generated from a variable. there may be other values we can get but I want only the last one beofre comma (,).
From the string DWDate,Email,UserID,ID,LoanNum,PersonEmail,LoanDate,Paymt I want only "Paymt"
Can you please help me?
March 14, 2016 at 6:17 am
You want the string after the last comma?
The one before the last comma would be LoanDate
DECLARE @str VARCHAR(250) = 'DWDate,Email,UserID,ID,LoanNum,PersonEmail,LoanDate,Paymt'
SELECT REVERSE(LEFT(REVERSE(@str), CHARINDEX(',', REVERSE(@str))-1))
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 14, 2016 at 6:26 am
Hi GilaMonster,
You are terrific. It works like a charm!!
Thanks you so much
March 14, 2016 at 7:09 am
How about reducing some steps?
DECLARE @str VARCHAR(250) = 'DWDate,Email,UserID,ID,LoanNum,PersonEmail,LoanDate,Paymt'
SELECT RIGHT(@str, CHARINDEX(',', REVERSE(@str))-1)
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy