Showing posts with label delimited. Show all posts
Showing posts with label delimited. Show all posts

Wednesday, March 28, 2012

import multiple text files?

Hello,

I am kind of new to Sql Server 2005.

I figured out how to use the import data wizard to import a delimited text file.

But I need to find a way to import many delimited text files at once.

does anybody know if this can be done in Sql Server 2005? and how?
thanks in advance,Hi,

you should probably use integration services for that. SSIS has a special task for that which will loop though a directory and inmport all text files which fit into the filter specified before.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

Monday, March 26, 2012

Import HTML and Tab delimited into SQL

Hi,
I need to import files from either HTML or Tab delimited format into SQL
Server. I imagine this would involve DTS and/or a DSN, but I'm not sure of
the details. I'm able to standardize the filename and directory using code,
so that's not a problem. Any ideas?
HTML? I don't think so. Tab delimited, you bet.
Yes, you would set up a DTS packages using the
Import / Export wizard.
If you want to script this and run it, check out this
VBScript code sample:
http://www.eggheadcafe.com/articles/20030923.asp
2005 Microsoft MVP C#
Robbe Morris
http://www.masterado.net
http://www.mastervb.net
"Eric" <Eric@.discussions.microsoft.com> wrote in message
news:C603F79A-3654-4785-B144-84909C69473E@.microsoft.com...
> Hi,
> I need to import files from either HTML or Tab delimited format into SQL
> Server. I imagine this would involve DTS and/or a DSN, but I'm not sure of
> the details. I'm able to standardize the filename and directory using
> code,
> so that's not a problem. Any ideas?

Friday, March 23, 2012

Import flat file into SQL Server 2005 Express

I am new to SQL Server, and migrating part of an Access application to
SSE. I am trying to insert a comma delimited file into SSE 2005. I am
able to run a BULK INSERT statement on a simple file, specifying the
field (,) and row (\n) terminators. I can also do the same with a
format file.

Here is the problem. My csv file has 185 columns, with a mixture of
datatypes. Sometimes, a text field will contain the field delimiter as
part of the string. In this case (and only in this case) there will be
double quotes around the string to indicate that the comma is part of
the field, and not a delimiter.

Is there any way to indicate that there is a text delimiter that is
only present some of the time?

If not, any suggestions on getting the data into SSE?

Many thanks for your input.

Cheryl(cabrenner@.optonline.net) writes:

Quote:

Originally Posted by

I am new to SQL Server, and migrating part of an Access application to
SSE. I am trying to insert a comma delimited file into SSE 2005. I am
able to run a BULK INSERT statement on a simple file, specifying the
field (,) and row (\n) terminators. I can also do the same with a
format file.
>
Here is the problem. My csv file has 185 columns, with a mixture of
datatypes. Sometimes, a text field will contain the field delimiter as
part of the string. In this case (and only in this case) there will be
double quotes around the string to indicate that the comma is part of
the field, and not a delimiter.


So a file could look like this:

2,34,Enter Sandman,Pat Boone
9,34,Zabadak,"Dave, Dee, Dozy, Mich & Tich"
8,981,"Rebel, Rebel",David Bowie

There is now way to get BULK INSERT to handle this file in that shape.
If I were faced with this file, I would write Perl script that replaced
the commas outside the "" with a different delimiter and then removed the
"". And it would not be trivial.

Most other people would probably try to write a package in Integration
Services, but I have never used Integration Services myself. And for your
part - SQL Express does not come with Integration Services, I believe.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||In message <Xns98B096E86FA00Yazorman@.127.0.0.1>, Erland Sommarskog
<esquel@.sommarskog.sewrites

Quote:

Originally Posted by

(cabrenner@.optonline.net) writes:

Quote:

Originally Posted by

>I am new to SQL Server, and migrating part of an Access application to
>SSE. I am trying to insert a comma delimited file into SSE 2005. I am
>able to run a BULK INSERT statement on a simple file, specifying the
>field (,) and row (\n) terminators. I can also do the same with a
>format file.
>>
>Here is the problem. My csv file has 185 columns, with a mixture of
>datatypes. Sometimes, a text field will contain the field delimiter as
>part of the string. In this case (and only in this case) there will be
>double quotes around the string to indicate that the comma is part of
>the field, and not a delimiter.


>
>So a file could look like this:
>
2,34,Enter Sandman,Pat Boone
9,34,Zabadak,"Dave, Dee, Dozy, Mich & Tich"
8,981,"Rebel, Rebel",David Bowie
>
>There is now way to get BULK INSERT to handle this file in that shape.
>If I were faced with this file, I would write Perl script that replaced
>the commas outside the "" with a different delimiter and then removed the
>"". And it would not be trivial.
>
>Most other people would probably try to write a package in Integration
>Services, but I have never used Integration Services myself. And for your
>part - SQL Express does not come with Integration Services, I believe.


Two things to add, both useful options if the amount of data is small.
First, the import filters in MS Access are better than those in SQL
Server. If the data will fit into an Access table that might just do the
trick. Second, spreadsheets have more flexible parsing options than
databases. It may be possible to load the data into a spreadsheet. That
allows different algorithms to be applied to different rows.

Lastly, text files can be opened and read by VBA code in any of the
office languages, or any of the .NET languages. Either could be used,
but writing code to cope with all of the possible options may take time.

--
Bernard Peek
back in search of cognoscenti|||Erland Sommarskog (esquel@.sommarskog.se) writes:

Quote:

Originally Posted by

So a file could look like this:
>
2,34,Enter Sandman,Pat Boone
9,34,Zabadak,"Dave, Dee, Dozy, Mich & Tich"
8,981,"Rebel, Rebel",David Bowie
>
There is now way to get BULK INSERT to handle this file in that shape.
If I were faced with this file, I would write Perl script that replaced
the commas outside the "" with a different delimiter and then removed the
"". And it would not be trivial.


In addition to Bernard's post, is not Excel able to read that format?
In such case open in Except, and save as a tab-delimited file and importing
that should be a breeze. (Assuming, of course, there are no tabs in the
data!)

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Thank you both for your suggestions. Yes, I was thinking that BULK
INSERT was not going to be able to handle this. I had thought about
dumping the file into an Access table first, but the file could be very
large (200,000+ rows). I am going to try the Excel spreadsheet idea.

Erland Sommarskog wrote:

Quote:

Originally Posted by

Erland Sommarskog (esquel@.sommarskog.se) writes:

Quote:

Originally Posted by

So a file could look like this:

2,34,Enter Sandman,Pat Boone
9,34,Zabadak,"Dave, Dee, Dozy, Mich & Tich"
8,981,"Rebel, Rebel",David Bowie

There is now way to get BULK INSERT to handle this file in that shape.
If I were faced with this file, I would write Perl script that replaced
the commas outside the "" with a different delimiter and then removed the
"". And it would not be trivial.


>
In addition to Bernard's post, is not Excel able to read that format?
In such case open in Except, and save as a tab-delimited file and importing
that should be a breeze. (Assuming, of course, there are no tabs in the
data!)
>
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
>
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

|||(cabrenner@.optonline.net) writes:

Quote:

Originally Posted by

Thank you both for your suggestions. Yes, I was thinking that BULK
INSERT was not going to be able to handle this. I had thought about
dumping the file into an Access table first, but the file could be very
large (200,000+ rows). I am going to try the Excel spreadsheet idea.


200000+ rows? Then Access is probably a better bet. Doesn't Excel stop
at 65536 rows?

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Erland Sommarskog wrote:

Quote:

Originally Posted by

(cabrenner@.optonline.net) writes:

Quote:

Originally Posted by

>Thank you both for your suggestions. Yes, I was thinking that BULK
>INSERT was not going to be able to handle this. I had thought about
>dumping the file into an Access table first, but the file could be very
>large (200,000+ rows). I am going to try the Excel spreadsheet idea.


>
200000+ rows? Then Access is probably a better bet. Doesn't Excel stop
at 65536 rows?


I think the latest version of Excel may have a higher row limit - which
only increases the tendency of newbies to misuse Excel as a "database".|||You are correct - Excel has a limit on the number of rows. I thought
about that after I sent the reply. So now I am looking at Access.

Here is my next question. I want to use OPENROWSET in a procedure to
get the data from Access into SSE. My code looks something like this:

INSERT INTO sse_table1 Select GFF.*
FROM OPENROWSET(
'Microsoft.Jet.OLEDB.4.0',
'path to mdb';'admin';'',
'Select * FROM access_table1
) as GFF

This works great. However, the location of the access database is only
known at runtime. I can pass the path as a parameter to the stored
procedure, but using it as a variable in OPENROWSET fails. Code looks
like this

CREATE PROCEDURE [dbo].[spImportBillingFile]
@.strTableLocation varchar(255),
@.btSuccess bit OUTPUT
AS
BEGIN

DECLARE @.strConnect varchar(255)
SET @.strConnect = @.strTableLocation

INSERT INTO tbl_ups_eInvoice_tmpData Select GFF.*
FROM OPENROWSET(
'Microsoft.Jet.OLEDB.4.0',
' + @.strConnect + ';'admin';'',
'Select * FROM tbl_ups_eInvoice_tmpData'
) as GFF

Set @.btSuccess = 1

END

Does OPENROWSET not allow a variable to be used?

Thanks again for the help.

Ed Murphy wrote:

Quote:

Originally Posted by

Erland Sommarskog wrote:
>

Quote:

Originally Posted by

(cabrenner@.optonline.net) writes:

Quote:

Originally Posted by

Thank you both for your suggestions. Yes, I was thinking that BULK
INSERT was not going to be able to handle this. I had thought about
dumping the file into an Access table first, but the file could be very
large (200,000+ rows). I am going to try the Excel spreadsheet idea.


200000+ rows? Then Access is probably a better bet. Doesn't Excel stop
at 65536 rows?


>
I think the latest version of Excel may have a higher row limit - which
only increases the tendency of newbies to misuse Excel as a "database".

|||(cabrenner@.optonline.net) writes:

Quote:

Originally Posted by

INSERT INTO tbl_ups_eInvoice_tmpData Select GFF.*
FROM OPENROWSET(
'Microsoft.Jet.OLEDB.4.0',
' + @.strConnect + ';'admin';'',
'Select * FROM tbl_ups_eInvoice_tmpData'
) as GFF
>
Set @.btSuccess = 1
>
END
>
Does OPENROWSET not allow a variable to be used?


No. Either you have to use dynamic SQL, or define a linked server on the
fly. The former is probably simpler. Look at
http://www.sommarskog.se/dynamic_sql.html#OPENQUERY for a similar example
on how to deal with the nested strings.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Thanks for all the info - I figured out how to use the dynamic sql.

Erland Sommarskog wrote:

Quote:

Originally Posted by

(cabrenner@.optonline.net) writes:

Quote:

Originally Posted by

INSERT INTO tbl_ups_eInvoice_tmpData Select GFF.*
FROM OPENROWSET(
'Microsoft.Jet.OLEDB.4.0',
' + @.strConnect + ';'admin';'',
'Select * FROM tbl_ups_eInvoice_tmpData'
) as GFF

Set @.btSuccess = 1

END

Does OPENROWSET not allow a variable to be used?


>
No. Either you have to use dynamic SQL, or define a linked server on the
fly. The former is probably simpler. Look at
http://www.sommarskog.se/dynamic_sql.html#OPENQUERY for a similar example
on how to deal with the nested strings.
>
>
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
>
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

sql

Monday, March 12, 2012

Import Data into XML

I have an XML File created to my specs. How do I import data into XML?
I have a PRN file, tab delimited, that I want to import, or convert
his PRN to Excel, which I can do and then import the Excel data into
XML? I created an XML file based off a DTD template. Now I need to
import data into this XML file.
Please help
Thanks,
Brian
You mean you want to "convert" your data into XML? Well, Office 2003 can do
it for you (using Word or XL). You could also have your own application read
through the file and general XML, or use XSL for generating the XML. Here is
one sample: http://www.devx.com/getHelpOn/10MinuteSolution/20356
HTH,
SriSamp
Please reply to the whole group only!
http://www32.brinkster.com/srisamp
"Brian Jorgenson" <bjorgenson@.charter.net> wrote in message
news:34ec3ea7.0407200738.3d09f58c@.posting.google.c om...
> I have an XML File created to my specs. How do I import data into XML?
> I have a PRN file, tab delimited, that I want to import, or convert
> his PRN to Excel, which I can do and then import the Excel data into
> XML? I created an XML file based off a DTD template. Now I need to
> import data into this XML file.
> Please help
>
> Thanks,
> Brian
|||Not convert, but import data into an existing XML file. Is there a way
to join the tags in XML to the field's in an Excel file so the right
data gets imported into the correct XML tag's.
"SriSamp" <ssampath@.sct.co.in> wrote in message news:<#UNqO6obEHA.1656@.TK2MSFTNGP09.phx.gbl>...[vbcol=seagreen]
> You mean you want to "convert" your data into XML? Well, Office 2003 can do
> it for you (using Word or XL). You could also have your own application read
> through the file and general XML, or use XSL for generating the XML. Here is
> one sample: http://www.devx.com/getHelpOn/10MinuteSolution/20356
> --
> HTH,
> SriSamp
> Please reply to the whole group only!
> http://www32.brinkster.com/srisamp
> "Brian Jorgenson" <bjorgenson@.charter.net> wrote in message
> news:34ec3ea7.0407200738.3d09f58c@.posting.google.c om...
|||XL 2003 allows you to map data in the sheet to specific tags in an XML.
HTH,
SriSamp
Please reply to the whole group only!
http://www32.brinkster.com/srisamp
"Brian Jorgenson" <bjorgenson@.charter.net> wrote in message
news:34ec3ea7.0407241902.6ab0c13a@.posting.google.c om...
> Not convert, but import data into an existing XML file. Is there a way
> to join the tags in XML to the field's in an Excel file so the right
> data gets imported into the correct XML tag's.
> "SriSamp" <ssampath@.sct.co.in> wrote in message
news:<#UNqO6obEHA.1656@.TK2MSFTNGP09.phx.gbl>...[vbcol=seagreen]
can do[vbcol=seagreen]
read[vbcol=seagreen]
Here is[vbcol=seagreen]
|||Very cool... i forgot that Office System is more XML based. I will
give this a try and kudos to you.
"SriSamp" <ssampath@.sct.co.in> wrote in message news:<eX#iICxcEHA.3728@.TK2MSFTNGP09.phx.gbl>...[vbcol=seagreen]
> XL 2003 allows you to map data in the sheet to specific tags in an XML.
> --
> HTH,
> SriSamp
> Please reply to the whole group only!
> http://www32.brinkster.com/srisamp
> "Brian Jorgenson" <bjorgenson@.charter.net> wrote in message
> news:34ec3ea7.0407241902.6ab0c13a@.posting.google.c om...
> news:<#UNqO6obEHA.1656@.TK2MSFTNGP09.phx.gbl>...
> can do
> read
> Here is

Wednesday, March 7, 2012

import CSV data to SQL Server database

Hello everyone,

I need help with a situation that iam facing right now.

Here is the problem:

I have a tab limited or comma delimited CSV file. I want to read the contents of that CSV file and import it in one of the tables in the database.

id firstname lastname
-- ---- ----
"1" "John" "Smith"
"2" "Louis" "Garcia"

I assume that the columns in the CSV files and the table in the database match the datatype.

What would be a good approach to do it ? If anyone have a code that does the job, please post it.

Thank You.Do you have Enterprise Manager? If so goto the "import data" menu.|||Or Use a Bulk Insert statement

BULK INSERT dbo.TableName FROM '\\yourMachine\filename.csv'
WITH (DATAFILETYPE = 'char',
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
FIRSTROW = 2 )|||Hi pkr,

I want to achieve this programatically using ASP.Net and VB.Net .....

Can you tell me any good resources on it please ?

Thank You.|||Hi John,

Do you have a code snippet in ASP.Net/VB.Net that shows how to use the bulk statement ??

Please help.

Thank You.|||Its just like any other SQL statement|||The Bulk insert statement is best kept to the confines of a Stored procedure and therefore you would make a call to the stored proc from your Data Access Layer within your asp.net application.

If your going to use a DTS package you can call this directly from the DAL and manage each step programmatically; if this is the path you want to take I have posted some c# code in the following post:

http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=697176

But i don't recommend it.

All the best, John|||thanks a lot John. it really helped me .

import complex Comma delimited text files into sql tables

I need to import comma delimited text files into sql tables. in one of the column, there is a comma in the string itself. e.g.

Cust_ID Name Phone Address1 Address2

Date that I have:

001,juia, anderson,4694568855,,Cedar Spring

The data does not have double quote as text qualifiers. but as you see, on the Name column, there is a comma, which is not a delimiter. can anybody give any suggestions on how i can deal with that? i would appreciate it so much.

thanksWink

There are several ways to accomplish this. Here are a few ideas.

1. The best, of course, would be to ALTER the table and add a FirstName column and use the current column for the LastName. It would then be so-o-o much easier to find someone by their LastName.

2. Change the delimiters on the input files.

3. Import into a staging table, and then combine the names (if you really must).

|||

Arnie, Thanks for the reply !

However, not all of the data has first name and last name. Some of them have no commas for first name and last name, some do, some even have firstname (and comma), middle name (and comma), and lastname. If i create another column, how do I deal with those that do not have comma in the name column?

Thanks,

|||


You have a complex problem.


It would be easiest to have the extraction process use a different delimiter. Then embedded commas would be simple to handle.


If you cannot effect a change in delimiter by the extraction process, you could create a staging table, with more than enough varchar columns to hold all possible combinations of falsely delimited data. And then execute a script that would assume that all columns up to the one containing a number (phone) was part of the name. You could then concatenate the parts into one field.

Not an ideal situation, but oftentimes, reality is messy.

|||Posted a similar response in the SSIS forums.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1424223&SiteID=1

Basically, we all agree here. The data is poorly put together and will be almost impossible to determine which column is where in a progmatic fashion.

Import and Overwrite DB from Text File

First off, I am not a DBA, not even remotely close. Anywho, I have been given the task of figuring out how to import from a comma delimited text file into 2 columns of an existing database. The task is as follows:

- A daily text file is created by a Unix DB and placed on a folder local to the SQL Server.
- I am to take this file and import into an existing MS SQL2005 DB that has 3 columns.
- AccountID, AccountName, DateRecordCreated
- The imported data has to overwrite all existing SQL DB data.
- This is to run automated on a daily schedule.

Being a SysAdmin, this sounds super simple to do but I have wasted 2 full days in trying to figure out how to make this happen using SSIS. All I want to know is if I am in the right track in focusing on SSIS for a solution. Any additional How To's would be greatly appreciated. BTW, the text file looks something like this...

AccountID,AccountName
A123456,Joe Smith, M.D.
A234567,John H. Dude,M.D.

Thanx much
Recipe as follows:

Control flow:
1 - Execute SQL Task to issue a SQL statement: "truncate table account_table"
1 - Data flow to load the CSV file to the data base

Data flow:
1 - Flat File Source
1 - OLE DB Destination set to use "Table or view - fast load"

Then setup a SQL Server Agent job to execute the SSIS package.

Friday, February 24, 2012

import a CSV delimited text file into a table

Hi,

Could you help me to write a script to import a CSV delimited text file into a sql server table.?

Thanks,

carlos

Hi,

you can use either a linked server or OPENQUERY for ahhoc querying the data, or the Import wizard of Management Studio. A sample of this would be:

http://p2p.wrox.com/topic.asp?TOPIC_ID=20163

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de|||

Thanks Jens, but it is too complex.

I am using BULK INSERT, but now I have a problem when a try to load a DATE value, I get error

Msg 4864, Level 16, State 1, Line 2

Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 4 (EffectiveDate).

The script is

BULK INSERT grouppolicy

FROM 'C:\datatoload\test.txt'

WITH (

FIELDTERMINATOR = '\t',

ROWTERMINATOR = '\n'

)

Can Somebody help me

Thanks,