Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1018923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:55:54+00:00 2026-05-16T10:55:54+00:00

OK the question title is vague, but here’s the problem. I have a list

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:55:55+00:00Added an answer on May 16, 2026 at 10:55 am

    Unless I’m missing something obvious, can’t you just concatenate the elements you want into the new fields?

    In the example below I have also removed the loop because it doesn’t appear to be necessary – however, I can’t say for sure without some details of your fnSplit procedure:

    UPDATE Files 
    SET Col_A = dbo.fnSplit(FileName, '_', 1),
        Col_B = dbo.fnSplit(FileName, '_', 2) 
            + '_' + dbo.fnSplit(FileName, '_', 3)
            + '_' + dbo.fnSplit(FileName, '_', 4),
        Col_C = dbo.fnSplit(FileName, '_', 5), 
        Col_D = dbo.fnSplit(FileName, '_', 6),
        Col_E = dbo.fnSplit(FileName, '_', 7)
    etc
    

    (From a usability point of view, it might be better to use more meaningful names for you columns)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry about the vague question title, but I have these typedefs here: typedef std::list<AnimationKeyframe>
The title may be a bit vague, but here's my goal: I have a
I'm not really sure how to title this question but basically I have an
Sorry about the vague title, but i didnt know how to ask the question
I'm sure that this is an extremely basic question but here goes anyway! I
First of all, I apologise for the vagueness of the question title and if
The title of this question is a bit misleading, but I couldn't summarize this
I am almost too embarrassed to ask this question, but here we go... I
Following on from a previous question, ( previous question here ), the problem I'm
I couldn't really come up with a proper title for my question but allow

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.