Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Parsing tab selimited text into SQL table Expand / Collapse
Author
Message
Posted Friday, March 9, 2012 12:11 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, March 12, 2012 6:42 AM
Points: 4, Visits: 6
Hello! I have a weekly tab delimited file that is currently being parsed row by row in .net code and then inserted into a new table. The table created has 503 columns with varying row counts from week to week. The current process takes way to long because each row is parsed one by one.
I'm looking desperately for a quicker way to accomplish this process.

Ingredients:
1. Tab delimited text file
2. MS SQL Server database
3. Program is run .Net

Has anyone run across a similar situation or can anyone suggest a time efficient way to get this done?
Thanks in advance for any help!
Post #1264566
Posted Friday, March 9, 2012 12:15 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 12:10 PM
Points: 1,619, Visits: 1,236
How about creating a batch that executes a BCP (Bulk Copy Program) script?

_________________________________
seth delconte
http://sqlkeys.com
Post #1264571
Posted Friday, March 9, 2012 12:18 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 12:10 PM
Points: 1,619, Visits: 1,236
OR execute BCP right from a scheduled SQL Agent job. Here's a similar script I've used for a CSV file (you can change it for tab delimited use):


declare @cmd varchar(1000)
set @cmd =
'bcp AdventureWorks.dbo.mytest in "C:\test.csv" -t "," -r -c -q -S MYSERVER -T'
exec xp_cmdshell @cmd



_________________________________
seth delconte
http://sqlkeys.com
Post #1264574
Posted Tuesday, March 13, 2012 1:57 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, September 26, 2014 7:33 AM
Points: 7,107, Visits: 12,660
If you use SQL Agent, there is no need to introduce an additional programming domain into the call stack. Ditch xp_CmdShell and call bcp from a step with type CmdExec.

SSIS would be an equally capable tool to use here as well.


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1266294
Posted Tuesday, March 13, 2012 2:15 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 12:10 PM
Points: 1,619, Visits: 1,236
opc.three (3/13/2012)
If you use SQL Agent, there is no need to introduce an additional programming domain into the call stack. Ditch xp_CmdShell and call bcp from a step with type CmdExec.

SSIS would be an equally capable tool to use here as well.

Nice, good call.


_________________________________
seth delconte
http://sqlkeys.com
Post #1266310
Posted Tuesday, March 13, 2012 5:53 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 5:19 PM
Points: 35,263, Visits: 31,749
opc.three (3/13/2012)
If you use SQL Agent, there is no need to introduce an additional programming domain into the call stack. Ditch xp_CmdShell and call bcp from a step with type CmdExec.

SSIS would be an equally capable tool to use here as well.


Ditch SSIS for an equally capable tool for this problem. Just use BULK INSERT and be done with it.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1266430
Posted Tuesday, March 13, 2012 5:59 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, September 26, 2014 7:33 AM
Points: 7,107, Visits: 12,660
Jeff Moden (3/13/2012)
opc.three (3/13/2012)
If you use SQL Agent, there is no need to introduce an additional programming domain into the call stack. Ditch xp_CmdShell and call bcp from a step with type CmdExec.

SSIS would be an equally capable tool to use here as well.


Ditch SSIS for an equally capable tool for this problem. Just use BULK INSERT and be done with it.

The "Fast Load Option" of the "OLE DB Destination" in SSIS implements BULK INSERT, same API.


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1266431
Posted Tuesday, March 13, 2012 6:57 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 5:19 PM
Points: 35,263, Visits: 31,749
opc.three (3/13/2012)
Jeff Moden (3/13/2012)
opc.three (3/13/2012)
If you use SQL Agent, there is no need to introduce an additional programming domain into the call stack. Ditch xp_CmdShell and call bcp from a step with type CmdExec.

SSIS would be an equally capable tool to use here as well.


Ditch SSIS for an equally capable tool for this problem. Just use BULK INSERT and be done with it.

The "Fast Load Option" of the "OLE DB Destination" in SSIS implements BULK INSERT, same API.


Of course it is. But you don't need to go anywhere near an SSIS installation with BULK INSERT. It can all be done in T-SQL along with the rest of the processing.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1266440
Posted Tuesday, March 13, 2012 7:49 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, September 26, 2014 7:33 AM
Points: 7,107, Visits: 12,660
Nary is the day when I am in an environment without an SSIS installation for use with ETL processing.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1266454
Posted Wednesday, March 14, 2012 6:52 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Today @ 6:37 AM
Points: 10, Visits: 2,161
If you need to do this from a .net application, load your data from the file into a DataTable and then use the SQLBulkCopy class (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx) to move the data to your database.
Post #1266665
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse