Thursday, November 7, 2019

Split string and take last element In sql

DECLARE @full_path VARCHAR(1000)
SET @full_path = '\\SERVER\D$\EXPORTFILES\EXPORT001.csv'


SELECT SUBSTRING( @full_path , LEN(@full_path) -  CHARINDEX('\',REVERSE(@full_path)) + 2  , LEN(@full_path)  )


Result :
EXPORT001.csv


Syntax

 select url,
(CASE WHEN CHARINDEX('/', url, 1)=0 THEN url ELSE RIGHT(url, CHARINDEX('/', REVERSE(url)) - 1) END) AS ResultValue
from(
    select 'Articles/Search/ArtMID/2681/ArticleID/2218/Diet.aspx' as url union
    select 'OurStory/MD.aspx' as url union
    select 'AMD.aspx' as url
)dummytablename

Result value :



No comments:

Post a Comment

Mixed Content: The page at xxx was loaded over HTTPS, but requested an insecure

 Mixed Content: The page at ' https ://www.test.com/signup.aspx' was loaded over HTTPS, but requested an insecure script ' http ...