Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SQL and SSIS help please

Posted on 2011-02-11
8
232 Views
Last Modified: 2012-05-11
Hi there,

Can anyone help with this please. I am trying to create an ssis package to handle the following. A csv file needs to be inserted into a table. An example csv looks like this.

B, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3, 30, 31, 32
CV, 1, 10, 11, 12, 13, 2, 21, 22, 23, 3, 31, 32, 33, 34, 35, 36, 37, 4, 47, 5, 6, 7, 8, 9

The number of columns can vary.

My ultimate aim is to populate a table with one column, so the above data would look like this.

B1
B10
B11
B12
B13
..
CV1
CV10
CV11
...

etc

Can someone help with this please?


0
Comment
Question by:Fulgent
  • 4
  • 4
8 Comments
 
LVL 11

Expert Comment

by:rajvja
ID: 34869329
Hi

You can use script task and write some dotnet code as below


            connectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + importFolder + ";"
            conn = New Odbc.OdbcConnection(connectionString)

            da = New System.Data.Odbc.OdbcDataAdapter("select * from [" + fileName + "]", conn)
            da.Fill(dt)

you can query the dataset table and get your value and save to a variable
Then run the next task on this value
0
 

Author Comment

by:Fulgent
ID: 34869475
Thanks for the reply, couple of questions ..

Does the destination table have to exist before ssis can write to it, or can it build the table dynamically (the csv files will have a varying number of columns)

Say I have a table like this

Pcode      Val1      Val2
A      1      2
B      1      NULL
C      9      14

What SQL would I need to create a single column table like this?

A1
A2
B1
C9
C14

0
 
LVL 11

Expert Comment

by:rajvja
ID: 34869556
Hi

You can do both ways.
If the table already exists, you can map the columns returned by script task.
Or, you can create table with in the script task and insert into the table from the values returned from csv file.
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:Fulgent
ID: 34869593
Can you help with the SQL?
0
 
LVL 11

Accepted Solution

by:
rajvja earned 500 total points
ID: 34869663
Hi

  Find the attached code. I have done this in my prev project. This will give you an idea.

 ProcessCSV-File.txt
0
 

Author Comment

by:Fulgent
ID: 34869688
I can see how that uses bulkcopy to get the data into a table using ssis.

What I need is the sql to create my 1 column table?
0
 
LVL 11

Expert Comment

by:rajvja
ID: 34869750
Hi,

You can create the table with single column(create table mytable (col varchar(50))
Execute that script. Once you get the csv file into columns. Loop through each column and insert into the table.
0
 

Author Comment

by:Fulgent
ID: 34869858

I would prefer to use sql to make my 1 column table, can anyone help?
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

856 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