Solved

SQL String with DTS, using split string

Posted on 2014-01-08
6
437 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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

920 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

12 Experts available now in Live!

Get 1:1 Help Now