Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two table Table1 and Table2.

Table1 one has two column name Name and Adress.

This Address column has some data like SP.BD.COM, UP.SD.CP.COM etc.

I want to parse those data using sql and want get the last portion after parsing this data. Suppose after persing the SP.BD.COM I want to get BD.COM and after parsing UP.SD.CP.COM I want to get CP.COM. Before insert data into Table2 how can I remove first all dot portion and can get only last dot portion ?


SQL
INSERT INTO Table2
SELECT * FROM Table1;
Posted

SQL is not so good at string manipulation ,but has its basic string functions to use - http://msdn.microsoft.com/en-us/library/ms181984.aspx[^]
For you this may help:
SQL
DECLARE @VALUE AS NVARCHAR(MAX)
DECLARE @POS AS INT

SET @VALUE = 'UP.SD.CP.COM'
SET @POS = CHARINDEX('.', REVERSE(@VALUE), CHARINDEX('.', REVERSE(@VALUE)) + 1) - 1

SELECT RIGHT(@VALUE, @POS)
 
Share this answer
 
You can use logic with little modifications as described here:
http://stackoverflow.com/questions/2647/how-do-i-split-a-string-so-i-can-access-item-x[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900