Dynamically Generate Format File For OPENROWSET – SQLServerCentral

Dynamically Generate Format File For OPENROWSET

By Joey Moelands2016/04/18
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;
Goodluck,
Joey Moelands
Advertisements

Author: Protiguous

C# Software Developer, Father, and seeker of Truth.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s