Solved

SQL String with DTS, using split string

Posted on 2014-01-08
6
431 Views
Last Modified: 2014-01-09
I have a derived Column transformation in my DTS package that gets a Job number using an expression:

SUBSTRING(@[User::CurrentExcelPath],51,12) where (@[User::CurrentExcelPath] contains the filepath.

My job numbers have changed where length will not work.

I need to change to a split string.
My End goal is to strip out the job numbers from a given path. The below is 2 examples of a path

Example #1
W:\ProcessFiles\Labor_Sheet_Importation_123\ JOBNO_2014-01-01014_11331_URI- Daily Labor-Culpepper Recon 1-2-14.xlsm
Example #2
W:\ProcessFiles\Labor_Sheet_Importation_123\ JOBNO_2014-01-0001-RECON_11331_URI- Daily Labor-Culpepper Recon 1-3-14.xlsm

end result for Job Number will be:

"2014-01-0104"
"2014-01-0001-RECON"


How can I change this to strip out the job Number using a split string and will
derived column transformation Expression accept a split string?

The number of  underscores will always be the same, 3, but the lenght may vary from 12 to 18 now.
0
Comment
Question by:BKennedy2008
  • 4
6 Comments
 

Author Comment

by:BKennedy2008
ID: 39766051
It appears I cannot use a derived column to pull this out, I guess I would need a script to pull this out in my data flow
0
 
LVL 34

Accepted Solution

by:
Brian Crowe earned 250 total points
ID: 39766073
try using CHARINDEX

SELECT SUBSTRING(@filepath, CHARINDEX('JOBNO', @filepath) + 6,
      CHARINDEX('_', @filepath, CHARINDEX('JOBNO', @filepath) + 6) - CHARINDEX('JOBNO', @filepath) - 6)

replace @filepath with @[User::CurrentExcelPath]
0
 

Author Comment

by:BKennedy2008
ID: 39766098
Am I going to use the above in a script component? Such as the image in my data flow below?
 Data flow
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 40

Assisted Solution

by:Sharath
Sharath earned 250 total points
ID: 39766113
If you are looking for SQL solution, you can try this.Dump all raw data from CurrentExcelPath into a variable in a stage table and you can extract the needed string.
		 
select parsename(replace(replace(reverse(substring(reverse(JobName),1,charindex('\',reverse(JobName))-1)),'.',':'),'_','.'),3) JobName
  from test

Open in new window

http://sqlfiddle.com/#!3/20320/11
0
 

Author Comment

by:BKennedy2008
ID: 39766149
I think the script component is the path I would like to take, just need to figure out how to assign the input and output of the variables, the input being the @[User::CurrentExcelPath]
0
 

Author Closing Comment

by:BKennedy2008
ID: 39769361
Thanks for the help. I used a Script Component and used split function and set a variable to the JobNO Part. More coding than I wanted, but got the trick done.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
get most recent and second most recent date in SQL Server 24 47
mySQL Syntax 7 12
select over clause 1 15
SQL Query 3 0
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now