Click here to Skip to main content
15,916,600 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a SQL table with multiple columns
Column [INI"] is a "varchar" that I would like to extract data from
Here is a sample [INI] value
\\ngic.com\fs\APPS\NPS\SQA\standard\XMLs\FL\FL IN MC\FL IN MC 01.xml
How can I extract the data following the last '\'?
SQL
SELECT TOP (1000) tests.id
      ,[INI]
      ,[App]
      ,[SubApp]
      ,[Environment]
      ,[Comment]
      ,[Heartbeat]
      ,[UpdatedBy]
      ,[Timestamp]
  FROM [QATestData].[dbo].[Tests] tests


What I have tried:

I have tried
(select value from STRING_SPLIT(ini,'\') ) as testcasename
Posted
Updated 18-Jul-18 6:53am
v2
Comments
CHill60 18-Jul-18 11:43am    
We can't use your link. Post a sample of the file here
lovinlife045 18-Jul-18 12:06pm    
Sorry for the confusion. That's not a link.
It is the data in the [INI] column

Here is a sample of the data in the [INI] column:
\\ngic.com\fs\APPS\NPS\SQA\standard\XMLs\FL\FL IN MC\FL IN MC 01.xml

I wish to extract all of the data following the last '\', in this case
"FL IN MC 01.XML"

Thank you
CHill60 19-Jul-18 4:11am    
:laugh: Sorry about the misunderstanding. Glad you got a solution

Assuming SQL server, you could do the following:

select REVERSE(SUBSTRING(REVERSE(INI), 1, CHARINDEX('\', REVERSE(INI))-1))
FROM [QATestData].[dbo].[Tests] tests
 
Share this answer
 
Comments
lovinlife045 18-Jul-18 13:28pm    
Thank you. Your solution worked !!!
You will need to use a split function to basically create an array, and then follow that up by getting the value for the last element in the array.

I cannot give you specific code for this, as you did not provide which type of SQL you are using(MySql, Sql Server, et al). Also, not all versions of any particular type have that function built-in (eg Sql Server did not support prior to 2016)
 
Share this answer
 

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