I have the following link: /ABCDEF/ABCDEF/ABC/8921/154535
I need to insert only the last 6 numbers i.e. 154535
in a column in a table.
I have the following link: /ABCDEF/ABCDEF/ABC/8921/154535
I need to insert only the last 6 numbers i.e. 154535
in a column in a table.
Try below code:
Declare @s varchar(100) = '/ABCDEF/ABCDEF/ABC/8921/154535'
select REVERSE(SUBSTRING(REVERSE(@s),0,CHARINDEX('/',REVERSE(@s))))
Try below code:
Declare @s varchar(100) = '/ABCDEF/ABCDEF/ABC/8921/154535'
select substring(@s, patindex('%[0-9][0-9][0-9][0-9][0-9][0-9]', @s), len(@s))
You are assigning multiple rows to a variable. So, you get error : returned more than 1 query
Try below simple solution:
select DISTINCT REVERSE(SUBSTRING(REVERSE(@s),0,CHARINDEX('/',REVERSE(@s)))) from [dbo].[No_of_Views]
And if you want to insert
then:
INSERT INTO table_name --your table name
select DISTINCT REVERSE(SUBSTRING(REVERSE(@s),0,CHARINDEX('/',REVERSE(@s)))) from [dbo].[No_of_Views]