String Function in SQL-Substring,Reverse,CharIndex
Suppose You have String "~/ABC/PQR.xxx" in your tables
Now u Want to string PQR.xxx fromm above string
So For That Follow the Steps
1) Open NewQuery Window
2) Paste following Code
declare @str as varchar(200),@str1 as varchar(200),@rev as varchar(200)
set @str ='~/ABC/PQR.xxx'
select @rev = reverse(@str)
SELECT @str1 = CHARINDEX('/', reverse(@str))
select @str1,@rev'@rev',reverse(substring(@rev,0,convert(int,@str1)))
3) Execute the Code
4) You will get the Output Like that PQR.xxx
Now u Want to string PQR.xxx fromm above string
So For That Follow the Steps
1) Open NewQuery Window
2) Paste following Code
declare @str as varchar(200),@str1 as varchar(200),@rev as varchar(200)
set @str ='~/ABC/PQR.xxx'
select @rev = reverse(@str)
SELECT @str1 = CHARINDEX('/', reverse(@str))
select @str1,@rev'@rev',reverse(substring(@rev,0,convert(int,@str1)))
3) Execute the Code
4) You will get the Output Like that PQR.xxx
This comment has been removed by the author.
ReplyDeleteHi Shubhank,
ReplyDeleteGood work, but let know the user that the querys ur posting are for which DB. (SQl Server,ORACLE).
Regards,
Shashank Kharche
This comment has been removed by the author.
ReplyDeleteHi Shashank !
ReplyDeleteThanks for your suggestion.
I will take care for this in future.
Regards
Shubhank Upadhyay
There is Syntax Error in Line "set @str = ~/ABC/PQR.xxx'"
ReplyDeleteIt must be:
set @str = '~/ABC/PQR.xxx'
From,
BJ
Dear Mahotnahi !!
ReplyDeleteThanks for That !
Regards
Shubhank Upadhyay
Your blog is in a convincing manner, thanks for sharing such an information with lots of your effort and time sql server dba online training
ReplyDelete