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

Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi Shubhank,

    Good work, but let know the user that the querys ur posting are for which DB. (SQl Server,ORACLE).

    Regards,
    Shashank Kharche

    ReplyDelete
  3. Hi Shashank !

    Thanks for your suggestion.
    I will take care for this in future.

    Regards
    Shubhank Upadhyay

    ReplyDelete
  4. There is Syntax Error in Line "set @str = ~/ABC/PQR.xxx'"

    It must be:

    set @str = '~/ABC/PQR.xxx'

    From,
    BJ

    ReplyDelete
  5. Dear Mahotnahi !!

    Thanks for That !


    Regards
    Shubhank Upadhyay

    ReplyDelete
  6. 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

Post a Comment

Popular posts from this blog

Difference Between ArrayList and Generic.List C#/VB.Net

How to Use Not IN operator