January 4, 2013 at 12:19 pm
My goal is to parse out a company name and contact name that is the actual filename of the excel spreadsheet.
I will use this information in a sql server 2008 r2 database to obtain other related information for the company and contact person.
My problem is the file name is manually keyed in my the user who runs the sql server 2008 r2 reports (ssrs) on the standard edition.
Is there away you would suggest that I try to parse out the company and contact name from the file name? There are delimiters between the company and contact names how the delimiters may change.
You assume that I will pass the filename to the t-sql. However I would like to know how you would setup the sql to accomodate the various in delimiters that may appear and the various of where the delimiters would appear at?
Can you show me in code and/or point me to a reference on how to accomplish my goal?
January 4, 2013 at 12:27 pm
wendy we need some examples, i think;
splitting the name based on some character is easy; PARSENAME or the famous DelimitedSplit8K are two examples that come to mind;
but unless there is a naming convention, ie the first x segments constitute the company name, i don't know what i can offer.
With MySampleData(filename)
AS
(
SELECT 'wendy-elizabeth-inc-2013-01-04.txt' UNION ALL
SELECT 'lowell_Corporation.txt' UNION ALL
SELECT 'dwainc-LLC-LatestExport.txt'
)
SELECT
myfn.*,
MySampleData.*
FROM MySampleData
CROSS APPLY dbo.DelimitedSplit8K(REPLACE(filename,'_','-'),'-') myfn
Lowell
January 6, 2013 at 6:33 pm
Apparently Lowell was thinking of me for some reason (not sure why) when he posted so I couldn't help but chime in!
You might want to take a look at the PatternSplitCM FUNCTION described in the 4th article in my signature link. The article contains some examples of parsing out a filename from a string using that function. It might help to get you started.
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply