OK the question title is vague, but here's the problem. I have a list of filenames in the first column of a table called Files that I want to parse data from that are underscore delimited, however sometimes I want to skip the underscore. Every filename is in the form of:
distance1000_7_13_2010_1_13PM_AveryDennisonAD_2300008_10S_Lock.csv
So in order to get the date and the time, I want to split this column into the following form:
Col_A = distance1000
Col_B = 7_13_2010
Col_C = 1_13PM
Col_D = AveryDennisonAD
Col_E = 2300008
Col_F = 10S
Col_G = Lock.csv
If I could truncate the .csv off of Col_G, that would be great too, although it is not necessary. Here's the code I have so far where Col_B and Col_C of dates and times are not correctly parsed:
DECLARE @RowCount INT, @I INT
SET @RowCount = (SELECT COUNT(FileName) FROM Files)
SET @I = 1
WHILE (@I <= @RowCount)
BEGIN
DECLARE @FileName VARCHAR(1000)
SELECT @FileName = FileName FROM Files WHERE FileID = @I
UPDATE Files
SET Col_A = dbo.fnSplit(@FileName, '_', 1),
Col_B = dbo.fnSplit(@FileName, '_', 2),
Col_C = dbo.fnSplit(@FileName, '_', 3),
Col_D = dbo.fnSplit(@FileName, '_', 4),
Col_E = dbo.fnSplit(@FileName, '_', 5)
--etc.etc.
WHERE FileID = @I
SET @I = @I + 1
END
How can I modify the SET statements in order to 'skip' the delimiter sometimes (and include it in the new column data) and to use the underscore delimiter to split columns at other times?
I hope this is clear. Thanks in advance!