Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Extract data from delimited string SQL

$
0
0

I have a string in a table that I need to extract parts of into variables so I can make another string. I have been looking at STRING_SPLIT but can't make it do what I need.

My string

@path = 'C:\Working\Imaging\Migration\2017\3\1\7\5187990.TIF'

Basically I need to make a new variable, @CreationDate from @path. In this this instance, @CreationDate = 2017-3-1 7:00:00

I was trying to at least set the @year, @month....variables but that is where I am getting stuck making this code more efficient

This is what I got so far but it only sets the @year

SQL
declare@pathvarchar(max)declare@yearintdeclare@monthintdeclare@dayintdeclare@hourintset@path='C:\Working\Imaging\Migration\2017\3\1\7\5187990.TIF';withsplit_pathas(selectrow_number()over(orderby(select1))asid,valuefromstring_split(@path,'\'))select@year=...

Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>