Solved

SQL and SSIS help please

Posted on 2011-02-11
8
229 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:Fulgent
Comment Utility
Can you help with the SQL?
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 11

Accepted Solution

by:
rajvja earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

763 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

10 Experts available now in Live!

Get 1:1 Help Now