BCP Fixed Width File Import
Oct 19, 2007
I have a fixed width file that I only need a middle field imported.
The field I need starts at character 116 and is 15 character wide. What should my format file look like?
I have a format file that can import a field before it but this is data I don't need. How do you skip the first field?
View 3 Replies
ADVERTISEMENT
Dec 12, 2006
More SSIS woes. DTS was so much easier.
I have a flat file. It's fixed-with with CRLF record delimiters (a.k.a. Ragged Right format).
Some fields are null, and represented by the text NULL.
I'm trying to import the file into SQL via an OLE DB connection. The target table is a SQL 2000 data table. Two of the fields in the target database are of type smallint.
When I run PREVIEW on the data source (Flat File), everything looks good & correct. I added the convert columns task to convert my strings to smallint. This is where things go haywire.
After linking everything up, the conversion gives me a "Cannot convert because of a possible loss of data." All of my numbers are < 50, so I know this isn't the case. Another SSIS bogus error
My first instinct is the SSIS doesn't understand that NULL means null. I edited the file and replaced all instances of NULL with 4 emtpy string chars. Still no good. It seems to be having a hard time parsing the file now.
I dropped the convert task and tried editing the data source, and set the two smallint fields to smallint instead of string (SSIS formats). I get the same conversion error.
Changing the NULL values to 0 fixed the problem, but they're not 0. They're null.
Short of creating another script that converts all zeros to NULL using the aforementioned hack, I'm out of ideas.
I'm I missing something or is SSIS just incapable of handling nulls in fixed-width flat file formats?
TIA
View 7 Replies
View Related
Dec 6, 2013
I have like 100 columns and most of them work fine, but some will not work. I need to select the columns with correct width for fixed width flat file.
Here is typical SQL statment that works for most of them.
left(RTRIM(A.City) + Replicate(' ', 25) ,25) as [City]
The above one is not working, but many other works fine like the address. Why would it work for some, but not others?
It works fine if I use any char, but not space. i.e.
left(RTRIM(A.City) + Replicate('*', 25) ,25) as [City]
View 5 Replies
View Related
Oct 26, 2006
Ok, so I've been playing around with SQL Server 2005 64-bit Dev Edition in readiness to phase out my existing SQL 2000 box. I've been having difficulty with importing fixed-width text data with SSIS. To explain, we use a linux based ERP system which is stored in a non-standard, encrypted flat-file format. So, each evening, I have a cron job spin off some shell scripts that use the ERP's report tool dump all of the relevant databases I need into a fixed-width format text file. The ERP platform also has a db layout report which is also in text format, I use this file (mangle it with VB first) and dump it back out into the format used to make a DSN file.
DSN connector file (dbname.dsn)
[ODBC]
DRIVER=Microsoft Text Driver (*.txt; *.csv)
UID=admin
UserCommitSync=Yes
Threads=3
SafeTransactions=0
PageTimeout=5
MaxScanRows=8
MaxBufferSize=2048
FIL=text
Extensions=None,asc,csv,tab,txt
DriverID=27
DefaultDir=C:ADVDBIMPORTEDcommoncurrentadvdb009
DBQ=C:ADVDBIMPORTEDcommoncurrentadvdb009
Because ODBC/DSNs are nifty enough to use a schema.ini file to lookup the data types, length and field names, I used that same db layout file to generate that as well.
schema.ini:
[advdb009.txt]
Format=FixedLength
ColNameHeader=False
MaxScanRows=0
CharacterSet=OEM
Col1=AccountNumber Char Width 15
Col2=Description Char Width 41
Col3=ContraAccountNumber Char Width 15
Col4=Type Char Width 2
Col5=Status Char Width 2
Col6=PositionOnBalanceSheet Char Width 2
Col7=PostingStatus Char Width 2
Col8=JobCostingTemplate Char Width 2
Col9=DailyActivityAmount Float Width 15
*snip*
I then put this schema.ini file in the same directory as the text file containing the fixed-width data, and its ready to go. In 2000/DTS, I simply launch the import/export wizard, point my data source to "Other (ODBC Data Source)" and point to the DSN file I created. Select my destination as a new SQL table on my server. Then tell the import wizard to do a straight across data copy, no transformations (except drop the destination table)... Save it as a local DTS package and finish the wizard. Once the package is saved, I use dtsrun from a cmd line in a bunch of batch files to re-populate the updated data from my ERP system to SQL everynight at 3am. Next morning, I can run fresh reports on my sales, inventory and financials from data of the previous day using Crystal or OLAP.
Now enters SSIS... Using the SSIS import wizard it does not give me the option to use a DSN source like DTS did. I've tried the .NET Framework for ODBC but it doesn't recognize the schema files, unless I'm not doing it right. Using the flatfile import method from SSIS requires that I hand enter the data types, widths and field name. As I have over 4000 fields across 26 tables, this is not practical. I also don't want to be required to hand-code a SSIS package in visual studio to resolve this, because again, I have to hand-code the schema when I already have it in a known ODBC schema file.
People have told me to use the DTS runner built into the SQL 2005, unfortunately my attempts to use it have failed mostly because the packages were written in SQL2000/32bit and I'm running the packages on 64-bit SQL 2005. They've given me alot of compile errors in visual studio. I also won't switch to a 32-bit version of SQL2005, because thats the whole point of moving to the new version and 64-bit technology, I want the extra horsepower and memory handling.
Has anyone else had this problem? Can anyone point me in the right direction on how to handle my import issue? I've picked up a few SSIS books but all they talk about is moving data back and forth with known server types and using the SSIS designer, nothing specific to working with fixed-width files, DSN or ODBC methods. Google searches has also ended nowhere due to the newness of SQL2005/SSIS.
Any help would be appreciated.
View 7 Replies
View Related
Feb 13, 2007
Hi,
I am trying to create a program that transfers tables to flat files.
At this point in time, I have suceeded in created one that creates delimited files.
However, I am now trying to create fixed-width files as you can do with the SSIS designer, but programatically.
Is there a way to programatically determine the width of a column from the source table? I can not seem to find any kind of function or member that stores this information or allows me to retrieve it.
I know what I need to change in order to set a width for a column, but I just don't know how to find the width without just asking the user to provide one.
View 5 Replies
View Related
May 2, 2006
I am attempting to import a fixed width file into a SS2005 table and am having problems when importing a date that has no value in it. The table will allow nulls.
The date is in dd/mm/yyyy foramt and when there is no date then there are 10 spaces. When transforming the data I TRIM the data down using a derive transform script so all there is, is an empty string. When the file attempts to load I get the following message:
[OLE DB Destination [2238]] Error: There was an error with input column "paid_date" (2306) on input "OLE DB Destination Input" (2251). The column status returned was: "The value could not be converted because of a potential loss of data.".
How can it potentially lose data when there is nothing to lose?
I need some way of converting the empty string into a null. Has anyone got any ideas for me?
View 1 Replies
View Related
Mar 28, 2007
Export to Fixed width text file
I am trying to export a table to a fixed lenght text file, there is only flat file option and that does not put LF/CR at the end of row, is there any solution?
View 4 Replies
View Related
Jun 14, 2007
Hi,
I was trying to import a fixed-width file to a sql 2005 table.
The total record lenght is 1500. I was trying to import it to a single column.
The strange thing that's happening is: SSIS is inserting only the first 32 chars of the record and the remaining are gone. I tried using nvarchar(max) and varchar(max) but of no use.
I think something somewhere is going wrong but I was unable to figure it out. Earlier I was able to load a similar file into a single column table.
My Header row delimiter is {CR}{LF}
The preview pane shows the complete record but when it transfers to the table, I'm getting 32 chars only.
Can anybody suggest any ideas to figure this out?
Thanks,
Siva.
View 3 Replies
View Related
Mar 29, 2007
Export to Fixed width text file
I am trying to export a table to a fixed lenght text file, there is only flat file option and that does not put LF/CR at the end of row, is there any solution?
View 5 Replies
View Related
Dec 7, 2006
Hello,
I have a series of fixed width files, all with the same schema. I need to import the data into a SQL Server table. Each record in the flat file begins with 'D1'. The length of each record (string) is 380. There are cases where the record ends after position 193, and a new record appears in the current string beginning at position 194. So at position 194 'D' appears, and '1' appears at position 195.
In the flat file, I need to insert a line break after position 193 if position 194 = 'D' and if position 195 = '1'. I'm guessing I would do this with a Script Component Transformation. Once the file is edited, then I can bring the data into the table.
What might the script look like? If you have any suggestions, samples, or know of examples on the web you can point me to, please share.
Thank you for your help!
cdun2
View 2 Replies
View Related
May 29, 2006
Currently we're working on an SSIS package to extract data from a SQL Server database to several fixed width flat files.
Some of the data needs to be formatted/converted in a certain way
DateTimes need to be formatted in ISO8601Booleans need to be 0/1 instead of False/True...Has anybody any idea what the preferred approach (best practice) would be to do these conversions?Convert everything in the select query? What about readability of your query?
Do it somewhere in the package? If so, how?....
View 1 Replies
View Related
Jan 22, 2008
I'm using SSIS to do bulk inserts from fixed width files to about 20 tables in my SQL database.
The problem I'm running into is in creating Format Files for the bulk insert task to use. I've gotten the bcp command to create format files that will read csv files, but I can't seem to figure out how to get it to create one for fixed-width.
I know it can be done: http://msdn2.microsoft.com/en-us/library/ms191234.aspx
At the bottom (Section F) it shows an XML format file for reading a fixed-width file. When I manually create one of these to match one of my tables, the bulk insert worked fine.
Closest I've come is with this ( [] bracketed items are correct values, just censored here):
C:Program FilesMicrosoft SQL Server90ToolsBinn>bcp [database].[owner].[table] format
nul -c -f C:TableFMT.xml -x -S[Server] -U[Username] -P[Password]
My question is, what is the bcp command to create this sort of XML format file?
View 1 Replies
View Related
Feb 1, 2007
Hi,
There's a lot of information on importing data from text files, but not a lot on exporting data to text files... I've checked but found no info on this.
I'm trying to export data from SQL Server to a fixed-width flat file and wondering if I'm doing it the right way.
I use a view as source (using a OLEDB connection manager) and I can see the data without problem.
I defined a Flat File Destination (using a flat file connection manager). When setting up the flat file connection manager, I am asked for a file... Does this mean one should create manually a template file with the desired output format? So I used a production file as template since we're replacing an existing process.
After having set up everything, I run the SSIS only to see all the data on the same row. There are no CRLF...
When I create the file connection manager, there's no way to mention the row delimiter. In the properties I see a "Row Delimiter" field and when I try with "{CR}{LF}" it makes no difference. Interesting to note that, contrary to the HeaderRowDelimiter field, the RowDelimiter field has no drop-down control to give choices.
So I had to return the CRLF as the last field of the source view (SELECT .... ,'CRLF' = CHAR(13) + CHAR(10) FROM ...) to make it work.
Seems odd... Is it the way to go?
Thanks
View 7 Replies
View Related
Jul 29, 2015
I wasn't sure where to put this topic so I put it here since I figured it is a question that would apply to virtually any version even though I am using SQL Server 2005.
We have a vendor that sends us a fixed width text file every day that needs to be imported to our database in 3 different tables. I am trying to import all of the data to a staging table and then plan on merging/inserting select data from the staging table to the 3 tables. The file has 77 columns of data and 20,000+ records. I created an XML format file which I sampled below:
<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="RetNo" xsi:type="CharFixed" LENGTH="6"/>
[Code] ....
The data file is a fixed width file with no column delimiters or row delimiters that I can tell. When I run the following insert statement I get the error below it.
BULK INSERT myStagingTable
FROM '.........myDataSource.txt'
WITH (
FORMATFILE = '.........myFormatFile.xml',
ERRORFILE = '.........errorlog.log'
);
Here is the error:
Msg 4832, Level 16, State 1, Line 1
Bulk load: An unexpected end of file was encountered in the data file.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
View 1 Replies
View Related
Aug 28, 2007
We're having issues exporting a set of data from SQL to a fixed width flat text file by just doing a right click on the DB, then choosing Tasks > Export Data. You can not specify a row delimiter when you choose a Fixed Width format. The only way around this that we've found is to specificy char(13) and char(10) at the end of the SQL select statement. Without row delimiters you end up with 1 giant record rather than 20,000 regular sized records. Is there any other way around this that we're missing?
Using Ragged Right is not an option either since the record lengths will be inconsistent if the last field doesn't contain a consistent length to the data.
Thanks,
Mike
View 16 Replies
View Related
Sep 14, 2007
I have a text file that is comma delimited and im pulling it in with a flatfile connection manager. I want to read some of the data, then output another flat file but in a fixed column width. What settings do I made to the connection manager of the output flatfile ?
View 9 Replies
View Related
Oct 19, 2007
I am new to SSIS and am having trouble with automatically setting up the destination output columns.
I am sure there must be an easy way to do this.
My table (source) has 86 columns in it of varying lenghts.
In my connection magagers, I have created one for the SQL Server (source data) and one for the flat file (destination output).
I have also created an OLE DB source data object and a destination Flat File object and set them up to the respective connection managers.
Finally I have linked the source to the destination.
Now when I look at the source, it shows me all 86 columns.
When I open up destination, there are no columns set up.
Problem: do I have to type in all the columns manually in the connection manager for the Flat File?
I would think there would be some automatic way that it would self-populate the columns over to the flat file destination.
View 3 Replies
View Related
Oct 30, 2006
I am trying to export data from a query in SQL Server 2005 SSIS to a flat file destination. Everything works fine except the rows returned from my query are written to the flat file in one long string (i.e., without line breaks). I have tried appending a new line character to the rows returned from the query but that only throws an error when the package is executed. My rows returned from the query are 133 characters wide (essentially only one column per row) so I have set the properties accordingly for a fixed width file format with 133 character wide rows.
Any suggestions or ideas on how to correct this would be greatly appreciated.
Thank you,
Michael
View 3 Replies
View Related
Dec 7, 2006
I am sorry, I am posting this message again, since I did not get anyreply.I want to export a table into a "fixed width" file using SQL 2005import export wizard.This is the version I have:SQL Server 2005 - 9.00.2047.00For some reason it joins all the rows together. For EX: if the tableis like this:Create table Mytable (col1 varchar(50) null, col2 varchar(60) null,col3 varchar (100) Null)Insert into MyTable values ("abcdef", "12345", "8900")Insert into MyTable values ("xxxxxxx", "11111111", "22222222")Insert into MyTable values ("yyyyyyyyy", "5555555555555555","6666666666")Insert into MyTable values ("abcdef", "12345", "8900")Insert into MyTable values ("xxxxxxx", "11111111", "22222222")Insert into MyTable values ("yyyyyyyyy", "5555555555555555","6666666666")It is not exporting every row in a single line. Actually if I open itin "Ultra Edit", it is all in one line.I used to do this regularly with SQL 2000 import export wizard and itexported every row in one line.I looked at the setting:The header row delimiter has {CR}{LF}Code page has 1252 Ansi-Latin.In the Advanced tab:String:dt_str.I tried changing the header row delimiter to just {CR} or just {LF}.Also I tried changing the string to dt_text and nothing seems to help.Please help.Thank you
View 1 Replies
View Related
Jun 12, 2006
How do I delete columns in a fixed width column file connection object, after I've saved it I can't remove columns anymore?
View 1 Replies
View Related
May 19, 2008
Hi All,
I have a simple SSIS package that runs a query on the db and outputs a fixed width flat file. I have all my column widths defined and in the connection manager i can preview the output. Everything looks great. All the fields fall where they should and each record is on it's own line.
When i run the SSIS program and then go open my text file with a text editor the ouput is all on the same line. I have tried changing my file format from fixed width to ragging right and adding a row delimiter but that doesn't work either. I feel like i'm missing something small here. It could even be an issue w/ my text editor (although i've tried to open the text file in multiple editors). In the flat file connection manager I have my file defined to be 187 characters long, So figure every 187 characters it should output a new line (it should add the carraige return right?).
Has anyone encountered an issue like this?
Any help would be much appreciated.
View 4 Replies
View Related
Jun 21, 2007
Hi-I have a sql database (2005) that I need to extract a report from that looks somehintg like SELECT * From Empl_Hours WHERE some_flag <> 'true' .The thing works fine, but the problem is this: I need to insert a record in the 1st row that looks like "Static_text"+row_count() +"more_static_text"where row_count is the actual # of rows that were retrieved. Thanks in advance for any help.DAn
View 3 Replies
View Related
May 14, 2007
I can't use DTS nor DTSwizard as I need to put it in a .sql and run it through a command line via .bat file (it's more for the users).
Each row ends with an EOL character, the fields are all fixed width, but I have a little problem here, some rows are empty but just with a EOL character.
How shall I go about it?
many thanks! :D
View 2 Replies
View Related
Jun 1, 2007
Is there a maximum width for fixed width column?
I'm trying to read in a flat file (which, admittedly, has one very wide column), and it keeps breaking because of truncation when it tries to read in the file.
Any ideas?
Jim Work
View 5 Replies
View Related
Apr 21, 2003
Will be getting new file for download from vendor to process in future. When I use DTS or Import wizard in sql server I get "could not find the selected row delimiter within the first 8kb of data, is the selected delimited valid? This is for a fixed length file. If I answer yes and continue everything is fine, until I get to the end of the record which it can't find. It basically lumps the records together. What is interesting, that if I import the same file in Access 2000, I don't get this problem. ANyone seen this before? Could not find anything on MSDN
View 2 Replies
View Related
Mar 3, 2006
I have a requirement to import a file of rows containing fixed length data. The problem is that each row can be one of 5 different formats (i.e. different columns) -- where the "type" of row is indicated by the first two characters of the row. Each row gets inserted into its own table.
Could I use a simple Conditional Split to route the rows? Or is the split for routing similiar rows? Anyways, problems are never this simple...
In addition, each "grouping" of rows is related. The "first" row is considered the "primary" row (and gets a row id via IDENTITY, whereas the remaining rows in the group are "secondary" rows and have foreign key references back the the primary rows id.
Given (using spaces to separate columns and CrLf to show "grouping"):
01 MSFT blah blah
02 blahblah blahblahblah
03 boring boringblah
01 AAPL blah blah
02 blahblah blahblahblah
03 boring boringblah
01 CSCO blah blah
02 blahblah blahblahblah
02 blahblah blahblahblah
03 boring boringblah
So, the first 3 lines are all related to a MSFT record which needs to be spread across multiple tables. The next three lines are all related to AAPL, And the next FOUR lines (yes, each record can have zero, one, or more secondary rows) are related to CSCO.
(If this is still not clear, all the "01" rows will be written to [Table1] with each row having an IDENTITY value. All the "02" rows will be written to [Table2] the a FK pointing to the correct [Table1] row. All the "03" rows will be written to... and so on.
Any ideas would be appreciated.
View 13 Replies
View Related
Dec 5, 2007
Hi,
I am trying to import a text file that has fixed length fields.
It also has column headers repeated in the file.
The text file is delimited by <CR><LF>.
Question 1
There are certain rows that end abruptly after a column for ex:
Row 1 <col1 data>.....<col2 data>.....<col3 data><CR><LF>
Row 2 <col1 data>.....<col2 data><CR><LF>
This seems to be throwing off the text file import as row 1 seems to be importing alright but row 2 gets ignored.
This not the behaviour I want. I want row 2 to also be imported and have a default of NULL for the columns that
are not specified.
Does anyone know how to achieve this?
Question 2
This is not that serious, but currently, I do not know of a way to ignore repeating column headers.
It would be nice if there was a way, but I can always resort to T-SQL based data cleaning after the import.
Thanks.
Shailen Sukul
|BSc|Mcsd.Net|Mcsd|Mcad|
Software Architect / Developer
Ashlen Consulting Services
http://www.ashlen.com.au
View 6 Replies
View Related
Apr 24, 2008
How do i import a Varying Column Width Flat file into a Table using SSIS?
I have a flat file that has 4 columns with varying width
Like I should read the file as
Col 1 - (1 to 10 Characters)
Col 2 - (12 to 21 Characters)
Col 3 - (22 to 35 Characters)
Col 4 - (36 to 38 Characters)
At the end of the record is a "LF"
I think "Fixed Width" Columns allow me to define a standard column length for all the columns.. Right?
Any thoughts on how to?
View 9 Replies
View Related
Apr 18, 2008
what is the best way to import fixed length text file to sql server using SSIS?
I was trying to using text file source and ole db destination..but since the text file has no columns and have different length per column and per line( it show only one column becasue it all concatnated), I can not map it to destination column..
How can I import it?
Here is the example of text file ( fixed with row delimeter)that i need to import to different columns...
010000000000000000001164.00023 YV
02004101 1 2008-04-OLL 43456 0000000001 2008-04-08
030000100000000000000000000007.00
047890 7556 YYU 779
View 8 Replies
View Related
Oct 31, 2005
I have a request to produce a SQL report that will be produced with fixed column width. For example see below Position Element LengthField Format 1-2 Column1 2 Alphanumeric 3-4 Column2 2 Alphanumeric 5-13 Column3 9 Chars Any idea how I can produce the report specified above? Thanks
View 1 Replies
View Related
Jun 6, 2006
I'm sending the results of an SSIS data flow to an fixed-width flat file output, but instead of getting separate rows of data, like so:
row1data...
row2data...
row3data...
etc...
I get:
row1data...row2data...row3data...etc...
Is there some setting I'm missing in either the flat file output or the file connection to turn this on?
View 3 Replies
View Related
Mar 8, 2005
Hi,
I have a customer who wants to send a fixed width file with 1400 characters per row.
Before I tell the 'OK', I was wondering if there is any limit to the length of rows when using a DTS .txt source.
Anyone know?
Thanks!
View 7 Replies
View Related
Feb 5, 2007
hi all,
is there a way to define a row delimiter to fixed width files? such as this one:
1122333
4455666
7788999
in this file i have 3 columns that are fixed (col1.width = 2, col2.width = 2, col3.width = 3) but have {CR}-{LF} as the row delimiter. when i try to create a flat file connection to these kind of files- he always reads the CR-LF as part of the file text, and there is no place where i can define the row delimiter if i have.
thanks for your help!!!
View 4 Replies
View Related