HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

String parsing: Extracting the filename from a URL

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
thefilenameparsingextractingfromstringurl

Problem

This is a link I have in a column of a table:

http://earthexplorer.usgs.gov/browse/etm/1/11/2000/LE70010112000130KIS00.jpg


There are like 1000's of rows like this.

  • Is it possible to extract the FileName like LE70010112000130KIS00 (without the path and filename extension) and put it in another column?



I am new to SQL Server.

Solution

I used this code to extract the FileName with Extension.

UPDATE TableName set ColumnName= right(Image_Link, CHARINDEX('/', REVERSE(ColumnName) + '/') - 1)


And this code to extract and update only FileName

UPDATE TableName  SET ColumnName= REVERSE(SUBSTRING(REVERSE(ColumnName),CHARINDEX('.', REVERSE(ColumnName)) + 1, 999))

Code Snippets

UPDATE TableName set ColumnName= right(Image_Link, CHARINDEX('/', REVERSE(ColumnName) + '/') - 1)
UPDATE TableName  SET ColumnName= REVERSE(SUBSTRING(REVERSE(ColumnName),CHARINDEX('.', REVERSE(ColumnName)) + 1, 999))

Context

StackExchange Database Administrators Q#127794, answer score: 3

Revisions (0)

No revisions yet.