January 4, 2011 at 2:36 pm
Hi I am new to this forum and somewhat new to sql.
The challenge I have is, I have a csv file with 50 columns and several of the columns contain multiple values separated with commas and other columns are separated by space.
I want to run a query that will separate these values w/out mixing other values from other rows.
Sorry if it sounds unclear.
Thanks
January 4, 2011 at 2:44 pm
If there are values within a column containing commas, how do you know what values belong to one column and what values belong to the next/previous one?
Is there any chance for you to get the structure of the file change to use a column separator that is not used within the columns?
January 4, 2011 at 4:19 pm
Hi Lutz and thanks for the reply.
Im not clear on your question # 2, but for the other question there is a column that identifies each row. here is a sample of the column names.
Column1 = session# ( single value)
Column2 = instructorname (multiple values separated by comma)
Column3 = instructorID (multiple values separted by comma)
Column4 = hours (multiple values separted by comma)
Thanks
January 4, 2011 at 4:21 pm
gecatoni (1/4/2011)
Hi Lutz and thanks for the reply.Im not clear on your question # 2, but for the other question there is a column that identifies each row. here is a sample of the column names.
Column1 = session# ( single value)
Column2 = instructorname (multiple values separated by comma)
Column3 = instructorID (multiple values separted by comma)
Column4 = hours (multiple values separted by comma)
Thanks
What is the separator for Column 2 and Column 3? Is that where the space is? Or is it another comma?
If it's another comma or a space, you need to go back to the originator and ask for a different delimeter, like a pipe. I assume that Instructor Names can have spaces, anyway.
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
January 4, 2011 at 6:44 pm
hi,
column 2 and 3 are separated with commas'.
thanks.
January 4, 2011 at 6:52 pm
hi,
Sorry, disregard my previous reply regarding columns 2 and 3, i misunderstood the question.
Columns 2 and 3 are separated by "pipe delimited". this is also true for all 50 columns. Now, the values in column 2 and 3 are separated by a comma and there are values in other columns that have "space" as a separator.
Thanks
January 4, 2011 at 7:56 pm
You will first have to load the csv file into a staging table. You can do this by creating a #temp table with 50 appropriately sized columns, and then using BULK INSERT, specifying a column delimiter of "|".
If you still need to separate "sub-columns" with comma delimiters, then you would need to utilize the DelimitedSplit8K function upon those columns in your staging table. Here is the latest version of the Delimited Split Function
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
January 5, 2011 at 9:15 am
Thanks Wayne, I will try your latest version of DelimitedSplit8k. I will keep you posted on my progress... wish me luck...
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply