Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Dynamically generate Format File For OPENROWSET tekst file import

By Joey Moelands,

Hello,

I was wondering why nobody ever wrote a script to dynamically generate a format file for BCP based on meta data. When you store youre target table and field definitions in meta data.

In steps (you need to program it your selve, don't want to make it to easy...)

1. Fill the meta data tables with your table definition

2. Create stored procedure for drop / create table from meta data definition

3. Create stored procedure for Select ... From table from meta data definition

And now the magic;

1. Dynamically generate a drop and create script for a table to be imported.

2. Dynamically generate the format file (needed for the insert into table, created by step 1).

3. Dynamically generrate the insert into statement for inserting into table (created in step 1).

This way you can fully dynamically do text file import for csv related files (instead of building thousands of SSIS packages to do bulk insert.....)

Some of the paramaters in the format file are now hard coded, offcourse all the variables in the format file can be put into the meta data. The definition of the XML needed is located here on MSDN;

http://msdn.microsoft.com/en-us/library/ms189327.aspx

 

Goodluck,

Joey Moelands

 

Total article views: 1393 | Views in the last 30 days: 10
 
Related Articles
FORUM

Dynamically Creating Indexes

Dynamically Creating Indexes

FORUM

Create Variable Dynamically

Create Variable Dynamically in Stored Procedure

FORUM

insert data using dynamic open row set

insert data using dynamic open row set

FORUM

DYNAMIC SELECT & INSERT QUERY HELP

DYNAMIC SELECT & INSERT QUERY HELP

FORUM

Issue on Insert datas in Dynamic Query

Issue on Insert datas in Dynamic Query

Tags
bcp    
bulk insert    
csv    
format file    
import files    
openrowset    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones