dbTalk Databases Forums  

Dynamic Column Mapping

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Dynamic Column Mapping in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
pm
 
Posts: n/a

Default Dynamic Column Mapping - 02-09-2005 , 03:25 PM






I need to load various excel file into SQL server. For every excel file
i have mapping table mapping excel column to SQL column. I am currently
dynamically generating insert statement from this mapping table and
then use to load records into sql server. For taking data from excel i
am using distributed queries. So basically i am dynamically preparing
statement like this

SELECT (following columns...) into Table1 FROM
OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0',
'Data Source=C:\MyExcelFile.xls;Extended Properties=Excel
8.0')...Data$

Only problem with this is that when it fails with following error
"String or binary data would be truncated.", I don't know which column
data is the culprit. And there are about 150 columns in the excel
sheet. Is there a way to find the culprit column? Or i have to try out
every column one by one by hit and trial.

Is it a good way of doing dynamic column mapping ?

Other way of doing dynamic column mapping would have been to write
script for data pump task. Is that a better way? I couldn't figure out
code for doing that.

Please help.

Thanks
pm


Reply With Quote
  #2  
Old   
Ilya Margolin
 
Posts: n/a

Default Re: Dynamic Column Mapping - 02-10-2005 , 07:53 AM






pm,

Get the list of all character or binary columns first. From here there are
two ways out:

1) subsequently exclude columns from the statement to see when it stops
breaking;
2) in Excel calculate maximum length for each such column and compare it
with the column definition in SQL server.

Ilya

"pm" <mittal.pradeep (AT) gmail (DOT) com> wrote

Quote:
I need to load various excel file into SQL server. For every excel file
i have mapping table mapping excel column to SQL column. I am currently
dynamically generating insert statement from this mapping table and
then use to load records into sql server. For taking data from excel i
am using distributed queries. So basically i am dynamically preparing
statement like this

SELECT (following columns...) into Table1 FROM
OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0',
'Data Source=C:\MyExcelFile.xls;Extended Properties=Excel
8.0')...Data$

Only problem with this is that when it fails with following error
"String or binary data would be truncated.", I don't know which column
data is the culprit. And there are about 150 columns in the excel
sheet. Is there a way to find the culprit column? Or i have to try out
every column one by one by hit and trial.

Is it a good way of doing dynamic column mapping ?

Other way of doing dynamic column mapping would have been to write
script for data pump task. Is that a better way? I couldn't figure out
code for doing that.

Please help.

Thanks
pm




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.