Parse string in SQL Server

Dear friends,
One of my colleagues was working on parsing on string in Sql server. I was thinking of old method like PATINDEX but he suggested a new way which is PARSENAME.

Below is basic syntax of it
PARSENAME (‘String with dot value’,index)
Example: suppose we have following string ‘234.456.678.454’
Now if we want to parse it and want 2nd item like 678 then you have to write following statement

DECLARE @StringToParse AS VARCHAR(200)
SET @StringToParse =’234.456.678.454’

When you run above statement then you will get 678.
The mandatory condition here is the string will have only “.” Dot delimiter.
I hope you will also enjoy this new learning.

Thanks & Best Regards,
Rajat Jaiswal


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s