Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

how do i load a txt file into sql server database

Posted on 2009-05-18
4
572 Views
Last Modified: 2012-06-21
i have a text file in which the files are in the following format (see attached text file)
now the original text file is 233 mb big

now I need to load that text file, without the surrounding inverted commas ("") on each file
how do i do it? so that when I load it, the data is in sync with the data types in the table

don't ask me to replace the inverted commas in the text file.
CREATE TABLE zztbNetworkSettlementExtract
( 
    ChargeCode INT
    ,TransactionNumber VARCHAR(50) 
    ,NoOfCharges INT
    ,PreviousTransactionNumber VARCHAR(50)
    , TransactionDate DATETIME
    ,ChargeType VARCHAR(10)
    ,ChargeDescription VARCHAR(50)
    ,NMI VARCHAR(10) 
    ,CheckSumValue INT	
    ,TariffCode VARCHAR(3)
    , Note VARCHAR(250)
    , ChargeStartDate DATETIME
    , ChargeEndDate DATETIME
    , TariffCodeDesc VARCHAR(250)
    , ReadType VARCHAR(2)
    , TariffDescription VARCHAR(50)
    , Consumption FLOAT
    , UOM VARCHAR(4)
    , Rate FLOAT	
    , GSTExlAmt FLOAT	
    , GSTAmt FLOAT	
    , GST VARCHAR(1)
)
 
 
---
 
BULK INSERT zztbNetworkSettlementExtract
    FROM 'c:\file.txt' 
    WITH 
    ( 
        FIELDTERMINATOR = ',', 
        ROWTERMINATOR = '\n' 
    )

Open in new window

testNuo.txt
0
Comment
Question by:manivineet
  • 2
4 Comments
 
LVL 15

Expert Comment

by:rob_farley
ID: 24409698
Try running the Import/Export Wizard. Go to Management Studio, right-click on your database, and choose "Import Data" from the Tasks menu.

There are plenty of options in there for handling the speech-marks.

Rob
0
 
LVL 7

Expert Comment

by:thiyaguk
ID: 24409744
0
 
LVL 31

Accepted Solution

by:
RiteshShah earned 500 total points
ID: 24409746
have a look at screen shot.
1.JPG
2.JPG
3.JPG
4.JPG
5.JPG
6.JPG
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24409761
once you have "TestNUO" table in SQL Server you can do something like below.

insert into zztbNetworkSettlementExtract
select REPLACE([column 0],'"',''),REPLACE([column 1],'"','').............from testnuo
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question