dbTalk Databases Forums  

Insert into different tables from a CSV file.

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


Discuss Insert into different tables from a CSV file. in the microsoft.public.sqlserver.dts forum.



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

Default Insert into different tables from a CSV file. - 11-13-2003 , 10:49 AM






I have a cvs file with a header, detail, and a footer with totals.

I' like to insert the header information into a table, the detail into
seperate table, and the footer total into another seperate table.

I've tried using Transform Data Task to insert the detail into a
table. Then using the lookup tab to insert the header and footer
information into another table.

May problem is I can't seem to get the data to insert into the header
and footer tables but I can get the detail data to insert into the
table without a problem.

I'm not even sure if this is the best way of inserting the data.


Here's my Transform Data Task ActiveX script.

'************************************************* *********************
' Visual Basic Transformation Script
'************************************************* ***********************

' Copy each source column to the destination column
Function Main()
If DTSSource("Col001") = "HEADER" then
DTSLookups("HeaderCount").Execute DTSSource("Col002")
else
If DTSSource("Col001") = "FOOTER" then
DTSLookUps("FooterTotal").Execute DTSSource("Col002")
else
DTSDestination("CompanyCD") = DTSSource("Col001")
DTSDestination("CustomerCD") = DTSSource("Col002")
DTSDestination("CalendarYear") = DTSSource("Col003")
DTSDestination("CalendarMonth") = DTSSource("Col004")
DTSDestination("SoldToPostalCD") = DTSSource("Col005")
DTSDestination("ShipToPostalCD") = DTSSource("Col006")
DTSDestination("SalesDollars") = DTSSource("Col007")
DTSDestination("StandardCost") = DTSSource("Col008")
DTSDestination("Units") = DTSSource("Col009")
end if
end if
Main = DTSTransformStat_OK
End Function


For the lookup tab

Insert for the Header:

INSERT INTO tblHeaderCount(HeaderCount)
VALUES (?)

Insert for the Footer:

INSERT INTO tblFooterSalesTotals(SalesDollars)
VALUES (?)

Any help would be greatly appreciated.
Mary

Reply With Quote
  #2  
Old   
Jeff Block
 
Posts: n/a

Default Re: Insert into different tables from a CSV file. - 11-13-2003 , 01:43 PM






You can use a three step bulk insert sql statement to accomplish this by
making use of the first_row parameter, you may need to do some parameter
driven work to get the last row # for the third step.

"mary bird" <mary.bird (AT) la-z-boy (DOT) com> wrote

Quote:
I have a cvs file with a header, detail, and a footer with totals.

I' like to insert the header information into a table, the detail into
seperate table, and the footer total into another seperate table.

I've tried using Transform Data Task to insert the detail into a
table. Then using the lookup tab to insert the header and footer
information into another table.

May problem is I can't seem to get the data to insert into the header
and footer tables but I can get the detail data to insert into the
table without a problem.

I'm not even sure if this is the best way of inserting the data.


Here's my Transform Data Task ActiveX script.

'************************************************* *********************
' Visual Basic Transformation Script
'************************************************* ***********************

' Copy each source column to the destination column
Function Main()
If DTSSource("Col001") = "HEADER" then
DTSLookups("HeaderCount").Execute DTSSource("Col002")
else
If DTSSource("Col001") = "FOOTER" then
DTSLookUps("FooterTotal").Execute DTSSource("Col002")
else
DTSDestination("CompanyCD") = DTSSource("Col001")
DTSDestination("CustomerCD") = DTSSource("Col002")
DTSDestination("CalendarYear") = DTSSource("Col003")
DTSDestination("CalendarMonth") = DTSSource("Col004")
DTSDestination("SoldToPostalCD") = DTSSource("Col005")
DTSDestination("ShipToPostalCD") = DTSSource("Col006")
DTSDestination("SalesDollars") = DTSSource("Col007")
DTSDestination("StandardCost") = DTSSource("Col008")
DTSDestination("Units") = DTSSource("Col009")
end if
end if
Main = DTSTransformStat_OK
End Function


For the lookup tab

Insert for the Header:

INSERT INTO tblHeaderCount(HeaderCount)
VALUES (?)

Insert for the Footer:

INSERT INTO tblFooterSalesTotals(SalesDollars)
VALUES (?)

Any help would be greatly appreciated.
Mary



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.