显示标签为“import”的博文。显示所有博文
显示标签为“import”的博文。显示所有博文

2012年3月29日星期四

Flow Control in SSIS

I am having a hard time with what appears to be something simple. I want to import an excel spreadsheet into a table on a daily basis from a command line. I created a package from the Import Wizzard in the SQL Management Studio and saved it. Since I want a clean table each day, my process needs to be create a temp table, import from the Excel file into the temp table. If that is successful, delete the original table and rename the temp table the original name. The point of this process is to provide for a fail-safe if there is some unforseen problem downloading the data on a particular day.

When I run the package, the first thing it does is delete the original table. I know this because the process shows the time that it finished is before anything else has started or finished. The time shown for the completion of the data flow task is about 2 minutes after that time.

This is maddening!!! The one thing I do not want to happen I can not seem to prevent. I have my control flow set on success. Why does it do this?

Are you using precedence constraints? You should have a flow like:

Create temp table(Execute SQL task) -- load temp table (Dataflow) --> delete orig. table & rename temp (Execute SQL Task)

The precedence constraint should be set upon success of the previous task

|||

Thanks for the reply. I was using contraints and what you descibe is how I put it in my original message. However, after a good night's sleep I see that in my package I the drop table task comes after the table is renamed, rather than before. It appears SSIS was trying its best to complete all those items the best it could.

After putting all in correct order, the package ran as it should.

Flow Control in SSIS

I am having a hard time with what appears to be something simple. I want to import an excel spreadsheet into a table on a daily basis from a command line. I created a package from the Import Wizzard in the SQL Management Studio and saved it. Since I want a clean table each day, my process needs to be create a temp table, import from the Excel file into the temp table. If that is successful, delete the original table and rename the temp table the original name. The point of this process is to provide for a fail-safe if there is some unforseen problem downloading the data on a particular day.

When I run the package, the first thing it does is delete the original table. I know this because the process shows the time that it finished is before anything else has started or finished. The time shown for the completion of the data flow task is about 2 minutes after that time.

This is maddening!!! The one thing I do not want to happen I can not seem to prevent. I have my control flow set on success. Why does it do this?

Are you using precedence constraints? You should have a flow like:

Create temp table(Execute SQL task) -- load temp table (Dataflow) --> delete orig. table & rename temp (Execute SQL Task)

The precedence constraint should be set upon success of the previous task

|||

Thanks for the reply. I was using contraints and what you descibe is how I put it in my original message. However, after a good night's sleep I see that in my package I the drop table task comes after the table is renamed, rather than before. It appears SSIS was trying its best to complete all those items the best it could.

After putting all in correct order, the package ran as it should.

sql

2012年3月26日星期一

flatfilesource(s) in a loop

I am trying to design a package to import the data of several .tx files into a table in sql server.

1) I created an execute task that truncates the sql server table i.e. truncate table tblContacts

2)
Placed a forrloop container with enumerator: foreach file enumerator
Folder points to the folder that holds the txt files
file: *.*
filename: fully qualified
variablemapping: User::FileName with Index 0

3)
placed a data flow task inside the forloop
this dataflow task has the following dataflow:
FlatFile Source: connection manager is pointing to one of the txt files
OLE DB Destination to place the txt data into tblContact in the database.

The question:
when the package is run, the tblContact gets populated only from the first txt file, i.e. the one which I placed in the flatfilesource connection manager.
How can I allow several files in the flatfilesource, instead of the one I have now...

Thanks

Firstly, in your For Each Loop, you could change filter from *.* to *.tx (not essential)

You need to make the connectionstring variable (ConnectionString is a property of your FlatFile connection Manager )

Click on your FlatFile Connection Manager (this is at the bottom of the BIDS screen).

Go to the properties of the CM, I mean the properties window that appears on the right of your screen.

Expand the Expressions property collection, and drill through to get the Property Expressions editor.

Choose property ConnectionString, and drill through the expression to get the Expression Builder.

Drag your variable (FileName) and drop it into the Expression box. I assume the FileName variable contains the entire file path and name.

Now it should work fine.

Flatfile into MSSQL

I currently have a flatfile with a seperate COBOL copybook. I need to be able to import all of it correctly into a db in mssql. Are there any *free programs that will turn the flatfile into some form for insertion into the db? What about csv format into the db?No need...just use bcp with a format file

What's the lrecl?

You could bcp the wole thing in as 1 column and the parse it to it's final destination...but creating a format file is the way to go...|||00002001 FLATFILE-REC.
000030 03 F-MASTER-PAR.
000040 05 F-MASTER-PARCEL-NUMBER PIC X(23).
000050 05 F-CARD-NUM PIC XXX.
000060 03 F-NUM-CARDS PIC XXX.
000070 03 F-APPR-PIN-NUMBER PIC X(22).
000080 03 F-PARCEL-LOCATOR.
000090 05 F-USER-CODES.
000100 07 F-USER-FILLER-1 PIC X(8).
000110 07 F-E-CODE PIC X.
000120 07 F-USER-FILLER-2 PIC X.
000130 03 F-APPR-DATE PIC 9(8).
000140 03 F-A-N-CODES.
000150 05 F-APPR-BY PIC XX.
000160 05 F-NEW-NOTICE PIC XX.
000170 03 F-APPR-UNUSED PIC 9(05).
000180 03 F-IMPROVEMENT-CODES.
000190 05 F-IMP-1.
000200 10 F-IMP-1-N PIC 99.
000210 05 F-IMP-2.
000220 10 F-IMP-2-N PIC 99.
000230 03 F-ACCOUNT-NUM PIC X(12).
000240 03 F-SOURCE-INFO-CODE PIC X.
000250 03 F-SUMMARY-VALUES.
000260 05 F-BLDG-DEPR-VALUE PIC 9(11).
000270 05 F-BLDG-RCN-VALUE PIC 9(11).
000280 05 F-XFOB-DEPR-VALUE PIC 9(11).
000290 05 F-LAND-VALUE PIC 9(11).
000300 05 F-SPECIAL-LAND-VALUE PIC 9(11).
000310 03 F-LAND-LINE-SUPERSET.
000320 04 F-LAND-LINE OCCURS 6 TIMES.
000330 05 F-USE-CODE PIC X(4).
000340 05 F-ZONING PIC X(6).
000350 05 F-UNIT-PRICE PIC 9(7)V99.
000360 05 F-NUMBER-UNITS PIC 9(7)V9(3).
000370 05 F-LAND-LINE-TYPE PIC X(2).
000380 05 F-LAND-LINE-VALUE PIC 9(9).
000390 05 F-FRONT PIC 9(5).
000400 05 F-DEPTH-XX PIC 9(5).
000410 05 F-DEPTH-FACT PIC 9V999.
000420 05 F-D-TAB PIC X.
000430 05 F-COND-FACT PIC 9V99.
000440 05 F-OTHER-ADJ PIC X(17).
000450 05 F-OTHER-ADJ-O11O REDEFINES F-OTHER-ADJ.
000460 10 F-SIGN1 PIC X.
000470 10 F-ROAD-FRONTAGE PIC 99.
000480 10 F-SIGN2 PIC X.
000490 10 F-TYP-ACCESS-OTHER PIC 99.
000500 10 F-SIGN3 PIC X.
000510 10 F-LOCATION-FACTOR PIC 99.
000520 10 F-SIGN4 PIC X.
000530 10 F-TOPO-FACTOR PIC 99.
000540 10 F-SIGN5 PIC X.
000550 10 F-SHAPE-FACTOR PIC 99.
000560 10 F-TYPE-RD PIC XX.
000570 05 F-LAND-NOTES PIC X(10).
000580 05 F-ADJ-UNIT-PRICE PIC 9(7)V999.


There is part of the copybook file starting with the FLATFILE-REC at the top and a Filler at the bottom. How do I go about changing this into a format file?|||Do you know what table(s) you need to put the data in?

Because I'm thinking this is 3 tables.

You would have a parent (the main master part) and 2 children.

1 For the Occurs, and another for the redefines..

And the more I think about it...I would set up a staging environment and use sql to so the work...

You can then also audit the data...

Got any low values?

Is this a 1 time thing *, or does it need to be repeated on a scheduled basis?

Do you know what DTS is?

Hell, I'd just bcp it in to a a table with 1 varchar(8000) column

How many rows are we talking about?

* Biggest lie in the industry|||Well, I was just going to place it into one table. This is definately a one time thing. I don't know what DTS is, and I am even surprised to be understanding any of this at all. I am pretty new to SQL/COBOL, but I am trying to learn. For the amount of rows, there are 38629 in total. The flatfile is around 100MB in size, and I have no chance on actually looking at the data through Excel or Access, but currently use KEDIT to view as a text file and to handle the size.|||We are talking about SQL Server correct?

Do you have SQL Server Client side tools installed?

Do you know what Enterprise manager or Query Analyzer is?

You're going to need them...

Do you have access to the sql server drives? Like can you map to a share?

You should put the file you want to import there.

And OK, you say 1 table...you can get away with the occurs part and have 6 repetitive columns...

But what about the redefines....can't do that unless you make everything char data|||REDEFINES allows you to reformat the same storage area.

OCCURS means that fields from line 330 through 580 will be repeated in the same order 6 times.|||Yes, I have all the tools via client side, and have an actual test server running on the same machine (So I don't fubar anything on the live server). 1 table was what my supervisor was looking for, but it seems like 3 would be a better solution. So what do I do from here?|||REDEFINES allows you to reformat the same storage area.

OCCURS means that fields from line 330 through 580 will be repeated in the same order 6 times.

holy sh-t...someone else knows COBOL?|||So... What do I do now?|||holy sh-t...someone else knows COBOL?Yes, and Algol, and Fortran, and Ratfor, and BAL, and...

-PatP|||We are talking about SQL Server correct?

Do you have SQL Server Client side tools installed?

Do you know what Enterprise manager or Query Analyzer is?

You're going to need them...

You need to answer the question....

BUT

I would create a table in Query Analyzer

CREATE TABLE myTable99(Col1 varchar(8000))
GO

I would ftp the file to the SQL Server server...please don't use IND$FILE 100 MG would take a awhile

I would then bcp the data in

EXEC master..xp_cmdshell 'bcp dbname.dbo.myTable99 IN c:\filelocation\filename -Sservername -Uuserid -Ppassword -c'

Then I would create a SELECT Statement using SUBSTRINGs

SELECT SUBSTRING(col1,1,32) AS F-MASTER-PARCEL-NUMBER
,ect for every column

I might even do conversion to the correct data types...

The I'd have a look

Then I would do a

SELECT...all your column defenitions
INTO myNewTable99
FROM myTable99

Which would create your final table

That's really how I would do it.

BUT!

I think most people would use DTS....in Enterprise manager...

It's a lot like importing data in to Access..but much more robust...|||Yes, and Algol, and Fortran, and Ratfor, and BAL, and...

-PatP

You left off Assembler and PL1...

What was that language we used to code on a commodore 64?|||I did leave off PL/1, even though I'm pretty fair at it (they still use it at the University!!!). You must have missed BAL.

I wrote Commodore Basic and 6502 Assembler on the Commodore, although I've always preferred the Apple ][.

-PatP|||There was that, and this

http://www.atarimagazines.com/compute/issue55/logo.php

And what'dya think...

Budster should install the clientside tools and dts the sucker in?|||I don't see 3 tables there, I see only 2 (where's blindman, he usually sees better than me ;))

Everything before OCCURS is your master table, and starting from OCCURS and including REDEFINES (you can redefine every field, its storage will not change) with the pointer to the master table would go to the child table.|||Yes, I have all the tools via client side, and have an actual test server running on the same machine (So I don't fubar anything on the live server). 1 table was what my supervisor was looking for, but it seems like 3 would be a better solution. So what do I do from here?

^^

I am in DTS import wizard, and now I just need help understanding how the cobol seperates the columns. For the flatfile, here is the first line (weird formatting with spacing and whatnot) Btw, I did not include the whole copybook.

0002 00059001 001001 1 06A5 1990010101 2020B5000000000054433 00000000000000000000000000000000000000410240000000 000000120A1 0001300000000606860AC000410237216000312507004074+0 4+00-20-10+00RP 0000676000 0000000000000000000 00000000000000000000000 000 0000000000 0000000000000000000 00000000000000000000000 000 0000000000 0000000000000000000 00000000000000000000000 000 0000000000 0000000000000000000 00000000000000000000000 000 0000000000 0000000000000000000 00000000000000000000000 000 0000000000 000000000 10001000 0000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000 00 000 00000000000000000000000000000000000000000 000000000000000000000000000000000000 190019000000 000000000000000000000000000000000000 190019000000 000000000000000000000000000000000000 190019000000 000000000000000000000000000000000000 190019000000 000000000000000000000000000000000000 190019000000 000000000000000000000000000000000000 190019000000 000000000000000000000000000000000000 190019000000 000000000000000000000000000000000000 190019000000 000000000000000000000000000000000000 190019000000 000000000000000000000000000000000000 190019000000014160258062001WDXV0003215000138706090 42001WDXV000918000013840508042001WDXV0000000000138 20238032001QCXV000000000013750273032001WDXV0051500 00WAS 760 AC MADE SPLITS IN 2001, REDUCED AC TO 606 SOLD 3 TIMES IN 2001 00000000000000000000000000 00000000000000000000000000 00000000000000000000000000 00000000000000000000000000 00000000000000000000000000 00000000000000000000000000 00000000000000000000000000 00000000000000000000000000 00000000000000000000000000 00000000000000000000000000 00000000000000000000000000 00000000000000000000000000 00000000000000000000000000 00000000000000000000000000 00000000000000000000000000 STRICKLAND THOMAS P D/B/A WAYSIDE RD 0004940000000000000000049400000000606860ACLL 32 59 62 227 LD16 606.86AC01600 00000494000000494000000000000000000000020020715RAI NTREE PROPERTIES 00 00|||Well...the data is fixed width format...

Just import the whole thing as 1 column and do what I mentioned...

Go to Data Transformation Services in Enterprise Manger, right click on the icon, choose all tasks, the choos import data.

Select the source data type as text...and follow the yellow brick road...

PS It's a wizard...

And rdjabarov, you don't think the redefines should be it's own table?|||OK, I have the whole file in a db now, but all as 1 column. What should I do now?|||You need to create a SELECT Statement that matches your layout...

First you need to determine the offset of each field so you can determine the starting position...

Actually make 3 SELECTS...make the first one up to the OCCURS columns...

What's the name of the table and what did you name the column?

Then I would create a SELECT Statement using SUBSTRINGs

SELECT SUBSTRING(col1,1,32) AS F-MASTER-PARCEL-NUMBER
,ect for every column

I might even do conversion to the correct data types...

The I'd have a look

Then I would do a

SELECT...all your column defenitions
INTO myNewTable99
FROM myTable99

Which would create your final table|||I was able to get the flatfile into a database using your suggestion, but now there is like wordwrapping going on. Also, Ive tried the SELECT statement, and it seems to work well on the first column, but how do I continue to do the rest of the columns?|||Word Wraping?

Where are you doing this? If it's in QA look at your settings...

And you need to count your offsets and use the starting position for each filed with the length as defined in your layout...|||OK, ya gotta work with me here...you reading all of this?

It's going to look like...

SELECT F-MASTER-PARCEL-NUMBER = SUBSTRING(Col1,1,23)
, F-CARD-NUM = SUBSTRING(Col1,24,3)
, F-NUM-CARDS = SUBSTRING(Col1,27,3)
, F-APPR-PIN-NUMBER = SUBSTRING(Col1,30,22)
, F-USER-FILLER-1 = SUBSTRING(Col1,52,8)
, F-E-CODE = SUBSTRING(Col1,60,1)
, F-USER-FILLER-2 = SUBSTRING(Col1,61,1)
, ect
FROM myTable99

Just open the txt file in Excel

The offsets are calculated like =SUM(C3+F3)-1|||OK. The query above works great! Thanks for all that. As for the wordwrapping, these are the steps I go through from DTS.

Choose Data Source -> Source = Text File

Select File Format -> Format = Fixed Field
File Type = ANSI
Skip Rows = 0
Row delimiter = {CR}{LF}

Now, right after that where it asks for the column positions, I get a preview of 3 lines. The first two are exactly what I want to see, yet the 3rd line looks like it has been wordwrapped. I have also tried setting "Row delimiter" to none and setting the Row Width either at 8000, or inbetween the black bars (which is what I am guessing represents a break, or enter in the data).|||Oh yah, can you explain the OCCURS and REPLACES again, being in different tables?|||Does each record have a unique key?

Id it does then for the occurs you would do

SELECT KeyName = SUBSTRING(Col1,n,m)
, OCCURS_FIELD_1 = SUBSTRING(Col1,n,m)
, OCCURS_FIELD_2 = SUBSTRING(Col1,n,m)
, Ect
UNION ALL
SELECT KeyName = SUBSTRING(Col1,n,m)
, OCCURS_FIELD_1 = SUBSTRING(Col1,n,m)
, OCCURS_FIELD_2 = SUBSTRING(Col1,n,m)
, Ect

Do that 6 time, 1 for each offset|||And I think I would forget about the redefines and just leave it as CHAR(17)

(mostly because it's be a pain...you'd have to check that the datatype of a column is numeric or not and the isolate the sets...still...)

for the occurs you need to have 6 union alls. I set it up so you can just add the offset

SELECT KEY-FIELDS = SUBSTRING(Col1,n,m)
--F-LAND-LINE OCCURS 6 TIMES.
, F-USE-CODE = SUBSTRING(Col1,151,4)
, F-ZONING = SUBSTRING(Col1,155,6)
, F-UNIT-PRICE = SUBSTRING(Col1,161,9)
, F-NUMBER-UNITS = SUBSTRING(Col1,170,10)
, F-LAND-LINE-TYPE = SUBSTRING(Col1,180,2)
, F-LAND-LINE-VALUE = SUBSTRING(Col1,182,9)
, F-FRONT = SUBSTRING(Col1,195,5)
, F-DEPTH-XX = SUBSTRING(Col1,196,5)
, F-DEPTH-FACT = SUBSTRING(Col1,201,4)
, F-D-TAB = SUBSTRING(Col1,205,1)
, F-COND-FACT = SUBSTRING(Col1,206,3)
, F-OTHER-ADJ = SUBSTRING(Col1,209,17)
, F-LAND-NOTES = SUBSTRING(Col1,225,10
, F-ADJ-UNIT-PRICE = SUBSTRING(Col1,235,10)
FROM myTable99
UNION ALL
SELECT KEY-FIELDS = SUBSTRING(Col1,n,m)
--F-LAND-LINE OCCURS 6 TIMES.
, F-USE-CODE = SUBSTRING(Col1,151+95,4)
, F-ZONING = SUBSTRING(Col1,155+95,6)
, F-UNIT-PRICE = SUBSTRING(Col1,161+95,9)
, F-NUMBER-UNITS = SUBSTRING(Col1,170+95,10)
, F-LAND-LINE-TYPE = SUBSTRING(Col1,180+95,2)
, F-LAND-LINE-VALUE = SUBSTRING(Col1,182+95,9)
, F-FRONT = SUBSTRING(Col1,195+95,5)
, F-DEPTH-XX = SUBSTRING(Col1,196+95,5)
, F-DEPTH-FACT = SUBSTRING(Col1,201+95,4)
, F-D-TAB = SUBSTRING(Col1,205+95,1)
, F-COND-FACT = SUBSTRING(Col1,206+95,3)
, F-OTHER-ADJ = SUBSTRING(Col1,209+95,17)
, F-LAND-NOTES = SUBSTRING(Col1,225+95,10
, F-ADJ-UNIT-PRICE = SUBSTRING(Col1,235+95,10)
FROM myTable99
UNION ALL
SELECT KEY-FIELDS = SUBSTRING(Col1,n,m)
--F-LAND-LINE OCCURS 6 TIMES.
, F-USE-CODE = SUBSTRING(Col1,151+190,4)
, F-ZONING = SUBSTRING(Col1,155+190,6)
, F-UNIT-PRICE = SUBSTRING(Col1,161+190,9)
, F-NUMBER-UNITS = SUBSTRING(Col1,170+190,10)
, F-LAND-LINE-TYPE = SUBSTRING(Col1,180+190,2)
, F-LAND-LINE-VALUE = SUBSTRING(Col1,182+190,9)
, F-FRONT = SUBSTRING(Col1,195+190,5)
, F-DEPTH-XX = SUBSTRING(Col1,196+190,5)
, F-DEPTH-FACT = SUBSTRING(Col1,201+190,4)
, F-D-TAB = SUBSTRING(Col1,205+190,1)
, F-COND-FACT = SUBSTRING(Col1,206+190,3)
, F-OTHER-ADJ = SUBSTRING(Col1,209+190,17)
, F-LAND-NOTES = SUBSTRING(Col1,225+190,10
, F-ADJ-UNIT-PRICE = SUBSTRING(Col1,235+190,10)
FROM myTable99
--ect

I gotta start charging soon...sql

Flat File with Nested Data

I am looking to import data into SQL Server 2005 using SSIS. I want to take data that is contained in a flat file and place it into the various appropriate tables in my system. The flat file contains nested data. For example...

Bob,Smith,555-5555,123~3.33|245~1.99,Active

So I want to build a package that brings in the records as follows

Client Table: First Name, Last Name, Phone, and Status (Bob, Smith, 555-5555, Active)

Order Table: OrderID, Amount (ID 123 @. $3.33 and another row ID 245 @. $1.99). If possible I would also like to tie the orders to the client record that was inserted.

My first question is if SSIS supports nested fields as in my example. Can it break a file by commas, then within a field by other delimiters? If so how do I do this, and if not what is the recommend way to accomplish this sort of task.

My second quesiton is if it can do that, can it tie the Client and Order data on the fly?

Thanks.

Looks like you could get what you want using multicasts, conditional splits, merges/unions, etc...

That's terribly messy source data, and if you can normalize it before bringing it into SSIS, you should do so.|||

The main problem I see you having with correllating a client with an order is not having an ID available. At least you won't have a Client ID until after you insert the client. This limits your ability to insert both within the same Data Flow Task.

One way to solve this is to generate an ID for the client before inserting.

If you had an ID you could then just use the Multicast Shape to send each row to multiple destinations. One destination would be the Client table, and the other would be the Order table. Your Data Flow would then look something like this.

Flat File Source --> Derived Column to add ID --> Multicast --> Client table, Order table

|||

I do not have control of the data feed. It is coming from a provider and therefore is out of my control. I also simplified the data greatly as there are multiple nested fields and nested within nested. So my initial dilema is just how to parse the data. Presently I have looked at two options, but both seem to be non-optimal and trying to figure out a better way to do this.

1. I did this with BizTalk. The problem is BizTalk is horrible on the performance side. I was able to convert the nested files into an XML structure and then send an XML message to a web service using code to import the data. This is just not a good solution.

2. I can import the data once. Then re-run and loop over the columns that can be nested untill all that data is pulled out. This works at a decent speed, but complex, subject to issues with file changes, prone to errors, etc.

So I have not found a way to do this easier... I will look at multicasts, conditional splits, etc but not seeing how i could use them to get the initial file split properly. If you have specific informaiton, links, examples, etc of how i can handle a multi nested flat file please let me know.

Thanks again.

|||

This is easy enough... Bear with me as I try to explain for you:
Bring in your source using the Flat File Source. Delimit on ",". The field names I used were FirstName, LastName, Phone, OrderData, Active. All are strings.
Next, I chose to create a composite key because I'm assuming that first name, last name, and phone number ensures a unique record in your dataset. Creating our own counter on each load may not guarantee uniqueness when inserting into your destination tables. So, throw a derived column transformation onto the data flow. Connect it to your source and create a new column, Key. Its expression is "FirstName+LastName+Phone". I left its datatype as unicode string, although you can cast it back to string if you'd like to fit your destination.
Then, add a multicast to your data flow. Connect it to the derived column transformation.
Next, add a destination for your client table. Hook it into the multicast. Take the FirstName, LastName, Phone, Active, and Key fields.
Add a script component to another output of the multicast transform. Select two fields as input columns, OrderData and Key. Select "Inputs and Outputs". Click on Output 0 and change the property, SynchronousInputID to 0. Next, add three output columns, "order", "key", and "value". Set order to string. Set key to which ever datatype you chose in the derived column above. Set value to numeric (perferrably) and set the precision/scale appropriately. Next up is the script:


Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Public Class ScriptMain
Inherits UserComponent
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
Dim arrayOrder As Array
Dim arrayOrderValues As Array
arrayOrder = Row.OrderData.ToString.Split("|"c)
For Each order As String In arrayOrder
arrayOrderValues = order.Split("~"c)
Output0Buffer.AddRow()
' I'm assuming that there is two and only two values for each order - ordernum, amount
' I perform no error checking of the data
Output0Buffer.order = arrayOrderValues.GetValue(0).ToString()
Output0Buffer.value = Decimal.Parse(arrayOrderValues.GetValue(1).ToString())
' Attach the key from the source row to each of the new rows we create from the nested data
Output0Buffer.key = Row.Key
Next
End Sub
End Class

Next, take the script, and hook it up to your second destination, which is for the order table. Take all three fields.
Done.
--Phil

|||I get where you are going with this and it may be my best solution. I think you answered my one thought, which is that with the given components available in SSIS it is not doable, it must be done with .NET or other code in the script component. I will try your sample code and work with it a little and see how it works. As i stated there is nested within nested, so I assume I can then repeat what you did and multicast a nested field to another .NET script that further processes the record?|||My code splits everything out...

An example source file I used:
Bob,Smith,555-5555,123~3.33|245~1.99,Active
Phil,Brammer,535-3333,347~2.14|671~5.14,Inactive
Test,Name,321-3211,347~2.14|671~5.14|127~1.26|876~4.20,Active

The output from what I documented above:
CLIENT
FirstName LastName Phone Active Key
Bob Smith 555-5555 Active BobSmith555-5555
Phil Brammer 535-3333 Inactive PhilBrammer535-3333
Test Name 321-3211 Active TestName321-3211

ORDER
order key value
123 BobSmith555-5555 3.330
245 BobSmith555-5555 1.990
347 PhilBrammer535-3333 2.140
671 PhilBrammer535-3333 5.140
347 TestName321-3211 2.140
671 TestName321-3211 5.140
127 TestName321-3211 1.260
876 TestName321-3211 4.200|||

I think this will be a solution... atleast for now. I am working with your sample code and testing some throughput... and working with the real data to see if I see problem, but it looks promising. Thank you for your help and suggestions.

One quick question is you mention to set "SynchronousInputID to 0." What is this and why? I am sure I could look it up and find info, but thought it might be easier coming straight from you. Thanks again.

|||Allows you to add rows to the data flow. This sets it to asynchronous.|||This all is working well. Thank you for your help... I think that this will server well to break the flat file feed and get it into the database. The last issue that I think I will face is I will not be using a composite key as you do to tie the records. The table is using an Identity column, so records that are inserted will get a new unique value. Is there an easy way to get the id out and tie it to the other inserts?|||Well, I hate identity columns, so...

You'll have to do a lookup task to lookup a record in the dataflow with it's associated record in the table. HOWEVER, you'll likely have to split the single dataflow I provided into two separate dataflows first.sql

Flat file with a standard of 4

Hi

I am trying to import a flat file into a table, and from there select values from the table and insert the appropriate values into different tables

The flat file is pipe delimited. I.E

File Example:

01|Name|Surname|BenCode|Counter||||||DateTime

02|Name|Surname|BenCode|SchemeID|SchemeName|

03|Name|Surname|BenCode|ID||||Date_From|Date_To||||||||||

04|Name|Surname|BenCode|SchemeID|SchemeName||||CodeID|CodeDescription||

All these different fields are in one flat file. (It would be nice if they were in 4 seperate flat files but they're not)

I want to take the file, where the ID = 01 then the data must go into table Q1

WHERE the ID = 02 then the data must go into table Q2 and so on

When i tried to do it with SSIS, it started creating columns according to the file, but it takes the first row and counts only that rows fields and calculates the columns based on the firs record, but some of the records have more fields than that of the first row.

If i can just get this flat file imported into a single table then i can split the data up based on the table.

Any ideas will be welcome. I'm quite new to SSIS.

Kind Regards

Carel Greaves

To handle the varying number of columns, you can bring each row in as a single column, then parse it in a script component. By adding multiple outputs to the script task, you can send each record type to it's own unique output. Here's a few examples:

http://agilebi.com/cs/blogs/jwelch/archive/2007/05/08/handling-flat-files-with-varying-numbers-of-columns.aspx

http://agilebi.com/cs/blogs/jwelch/archive/2007/07/12/processing-a-flat-file-with-header-and-detail-rows.aspx

2012年3月25日星期日

Flat File Source option missing in the Sql Server Import & Export Wizard.

Hi All,

I want to import a txt file data to a sql server database table, to do this i used sql server import and export wizard. In this when we choose a Data Source, the option Flat file source is not coming up in the combo box in the wizard.

I am using sql server 2005, Management Studio to do this.

steps 1. right click on the database --> all tasks --> import data --> sql server import export wizard --> choose data source dialog box....

please help me.

thanks in advance.

On my installation, flat file source is 4th on the list below the .Net Framework providers for odbc, oracle & sql serversql

2012年3月22日星期四

Flat File Records Dropped During Import

Hello,
I am attempting to import a fixed width flat file into a SQL Server table. When I import the file, 704 records don't make it into the table. I know this because if I do the import with MS Access 2003 into an Access table, all of the records from the flat file make it into the table. The flat files have a .txt extension.

The only possible problem that I can see is that some of the rows in the flat file do not contain the full set of characters. When I do the import into SQL Server and create a table on the fly, I still end up 704 records short. There are no error messages during or after the import.

I suppose I could isolate some of the missing records, put them into a different file and try to import them to see what would happen. Other than that, how do I begin to troubleshoot this problem? Are there known issues where records can be dropped from a fixed width file?

Thank you for your help!

cdun2I may have found the problem. The first record does not contain a full set of characters, and when I set up the fixed field column positions originally, I was not able to define the columns for the full string. Only the first one third of the row characters need to be imported, so I ignored this issue.

I have moved a single full length record to the top of the flat file, and the text file properties box now can 'see' the full string. I'll include the rest of the columns (which are not imported) and see if that works.|||No, that didn't work. I moved a record containing all characters to the top of the file, redefined the columns based on the full string, changed the column mappings, and reconfigured the transformations. When I did the import, the destination SQL Server table received even fewer records.

What can I do about this problem?

Thanks again.

cdun2|||If this is a one time only situation, why don't you just import the flat file into Access 2003 and then import the Access table to SQL server?|||What are you using to import the data? DTS? BCP?sql

Flat file processing dilemma

Hello,

How do I import data from a text file into columns (DB_table) that I have created in SQL server 2005?

Data in text file does not have any commas, semicolons, or spaces in between them.

Each instance in the text file consists of 109 characters (real numbers).

I also know that first 4 numbers go in particular field, next 4 go in another field, and next 6 are particular field, and so on.

I also have created columns in a table respectively.

Ravi,

have you tried using Fixed Width (or Ragged Right if you have row delimiters) format to process your files?

|||Use a fixed width file format and your problem is solved.

Flat File import question

I have a fixed width flat file that I'm trying to import, and I'm just about there. The last column that I'm struggling with, is a decimal amount. The data in the column looks like this 00000000500 and I need to dump it into a column as 5.000 In otherwords, the data in the file does not have any decimals, and I'm putting it into a sql server column that has the datatype numeric(11,4) I've set the InputColumnWidth to 11, the DataPrecision to 11 and the datascale to 2, and the value is still being imported as 500.000 Is there any way to achieve this other than using a script component to calculate the value? Thanks!

tee bone wrote:

I have a fixed width flat file that I'm trying to import, and I'm just about there. The last column that I'm struggling with, is a decimal amount. The data in the column looks like this 00000000500 and I need to dump it into a column as 5.000 In otherwords, the data in the file does not have any decimals, and I'm putting it into a sql server column that has the datatype numeric(11,4) I've set the InputColumnWidth to 11, the DataPrecision to 11 and the datascale to 2, and the value is still being imported as 500.000 Is there any way to achieve this other than using a script component to calculate the value? Thanks!

Add a derived column to take that value and divide it by 100 (or 1000, if you need)|||Thanks for the quick reply, so in other words there's no actual way to handle this situation in the connection manager itself? The solution that you have proposed will work, I was just trying to cut down on the time it takes for the package to process. We have to load a daily file that's about 300mb, so it takes a long time to process. I've cut it down to under a minute, but I was afraid adding another step in the flow would add quite a bit of time. I'm pretty new to SSIS, so please let me know if I'm worrying about it for no reason. Thanks!
|||On a side note, I'd go try this out and test it out for myself, but I'm going to have to apply this derived column transformation on about 150 columns, so I'm trying to get a good idea of what to expect before I get started
|||Yeah, the connection manager just reads the data as it is. What it currently sees (without a decimal point) is an integer. It is what it is. Either fix it in the source, or use a derived column. Sucks, yes, but that's the way it is.|||Sounds good, thanks for the help!

Flat file Import performance question

Hi there,

I have a question regarding 2 approaches importing data from a flat text file. I'm taking the approach suggested by Phil Brammer to use a checksum to see whether a row has exists, and if it does check whether it has changed.

http://www.ssistalk.com/2007/03/09/ssis-using-a-checksum-to-determine-if-a-row-has-changed

I would like to hear some opinions on 2 approaches:

1) Importing the data int a temp table first then do the data processing from the temp table.
Or
2) Importing the data by doing the data processing direcly from the text file without placing it in a temp table first.

A hunch told me that it will be faster doing approach 1 but I would like to hear some experienced opinions first Smile

Best regards
Mike

I would think #2 would be *slightly* faster just because there are less components at work.

With that said, I prefer #1 always because it quickly loads the data to a table which I can then use SQL to get the data out. This might be advantageous for sorting the data, filtering the data, joining the data to another table, etc... Basically I like to push as much work off to the database engine that I can. Sure, SSIS can merge (join) data sets together, but the database engine will do a much better job. Also, having the data staged will help me to restart the process should it fail, work in batches (perhaps) by loading more than one file to the table if needed, and guarantee that the data will be there when I need it in an environment that might not guarantee that the file will always be around for use.

|||Thanks Phil,

I really appreciate your valuable input.

Best regards
Mike
|||

If you can afford, I would suggest to test both approaches, in your own environment, and then base your decisions on that way collected (real) data.

Thanks,

Bob

sql

Flat file Import performance question

Hi there,

I have a question regarding 2 approaches importing data from a flat text file. I'm taking the approach suggested by Phil Brammer to use a checksum to see whether a row has exists, and if it does check whether it has changed.

http://www.ssistalk.com/2007/03/09/ssis-using-a-checksum-to-determine-if-a-row-has-changed

I would like to hear some opinions on 2 approaches:

1) Importing the data int a temp table first then do the data processing from the temp table.
Or
2) Importing the data by doing the data processing direcly from the text file without placing it in a temp table first.

A hunch told me that it will be faster doing approach 1 but I would like to hear some experienced opinions first Smile

Best regards
Mike

I would think #2 would be *slightly* faster just because there are less components at work.

With that said, I prefer #1 always because it quickly loads the data to a table which I can then use SQL to get the data out. This might be advantageous for sorting the data, filtering the data, joining the data to another table, etc... Basically I like to push as much work off to the database engine that I can. Sure, SSIS can merge (join) data sets together, but the database engine will do a much better job. Also, having the data staged will help me to restart the process should it fail, work in batches (perhaps) by loading more than one file to the table if needed, and guarantee that the data will be there when I need it in an environment that might not guarantee that the file will always be around for use.

|||Thanks Phil,

I really appreciate your valuable input.

Best regards
Mike
|||

If you can afford, I would suggest to test both approaches, in your own environment, and then base your decisions on that way collected (real) data.

Thanks,

Bob

Flat file import

I am trying to import a flat file with large rows into MS SQL Server. This flat file consists of about 100 columns of data, followed by a set of 10 columns repeated 50 times.

I would like very much to break the data apart in the import. What's the best way to handle it?

--
Dyolf KnipEither split up the file in two before the import, or, create an import table that consists of 100 columns, do the import, and work your way through the data finding out when the 10 column part starts. If you can select it, you can deal with it. It might work better or easier with a temp table with only one very wide column and do the processing after that.

Possibly there's a way to have one file and two fmt files that bcp uses to work on, inserting rows into two different tables. I'm not sure how to deal with the error's though.

Flat File Connection with quote encapsulated fields

I’m trying to evaluate SSIS for managing the import of files that have quote encapsulated fields, but not all fields are encapsulated. The fields are encapsulated to allow for embedded commas.

For example:

AAA,"BBB",CCC,"DDD","EEE","FFF",GGG,"HHHH",IIII

AAA,"BBB",CCC,"DDD","EE,E","FFF",,"HH,H",

When importing this file I have to alter the delimiter from column AAA to deal with the quote from column BBB like this:

{,}"

And BBB would look like

“{,}

Now I can go through each column for our files doing this by hand, but I wonder if there is some way to note that some fields are encapsulated. Thus it would be more wizard like. Or the ability to alter the Advanced fields while on the Preview or Columns to reduce the jumping across pages.

Also is the gramma for delimiters described anywhere?

Simeon

You should use the "Text Qualifier" property of the Flat File Connection Manager. In this case, you would specify " to be the Text Qualifier. Best part is if some columns are qualified, and some are not qualified, it will still handle them both.

Let me know if you have any problems using the Flat File Connection Manager.

thanks
Ranjeeta