Showing posts with label automatically. Show all posts
Showing posts with label automatically. Show all posts

Thursday, March 29, 2012

Create table,fields come from csv file

I want to create a table automatically,and fields come from a csv file

any idea? TIA

One way is using two packages and a configuration file.

I'm assuming that you are constructing the name of the table on the fly. Note that the table MUST always have the same format.

First create a sample of what you want your table to look like.

Package 1:
Create an SSIS package that loads data from a CSV file into that table.
Make the tablename come from a variable.
Put the variable in a configuration table

Package 2:
Create a variable that will contain the table name.
Create a variable expressions that has the sql to create the table using the variable previously defined.
Create a variable expression that has the sql to update the variable in the configuration table from Package 1
Create a SQL Task to create the table
Create a SQL Task to update the configuration table variable
Create an Execute SSIS package task to execute Package 1

Similarly you can extend this to the source by scanning directories for files and loading different CSV files into different tables.

Hope this helps,

Larry

Wednesday, March 7, 2012

create log file for a scrip

I'm am new to using SQL Server. In Oracle, when I create scripts to
manipulate data, I have a log file automatically created from within the
script by issuing the SPOOL command. Is there a similar functionality in SQL
server? Besides the log file which records each transaction. Thanks
Hi,
USE OSQL and redirect the output to a text file.
OSQL -USA -Ppassword -SServer -iC:\script.SQL >c:\log.txt
Thanks
Hari
SQL Server MVP
"Lee Ann" <Lee Ann@.discussions.microsoft.com> wrote in message
news:95E24AE5-39E0-4A95-A522-E9E9DF2B2215@.microsoft.com...
> I'm am new to using SQL Server. In Oracle, when I create scripts to
> manipulate data, I have a log file automatically created from within the
> script by issuing the SPOOL command. Is there a similar functionality in
> SQL
> server? Besides the log file which records each transaction. Thanks
|||Thanks Hari
"Hari Prasad" wrote:

> Hi,
> USE OSQL and redirect the output to a text file.
> OSQL -USA -Ppassword -SServer -iC:\script.SQL >c:\log.txt
> Thanks
> Hari
> SQL Server MVP
> "Lee Ann" <Lee Ann@.discussions.microsoft.com> wrote in message
> news:95E24AE5-39E0-4A95-A522-E9E9DF2B2215@.microsoft.com...
>
>