?
Solved

SQL and SSIS help please

Posted on 2011-02-11
8
Medium Priority
?
235 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
[X]
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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

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

Accepted Solution

by:
rajvja earned 2000 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.
Suggested Courses

762 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