Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
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

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: 1883 | Views in the last 30 days: 413
 
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