Solved

Remove quotations/text qualifier from text file when importing to MSSQL using ASP.

Posted on 2006-10-23
7
500 Views
Last Modified: 2008-01-09
I'm using ASP to execute the BULK INSERT statement to import data from an .xls file. The quotation marks are being inputted into the MSSQL DB table. I need to remove the quotation marks (the text qualifier) when importing data from the text file (.csv or .xls file) using ASP. I'm not having any permissions problems.

Please provide the needed code using the variables in the code provided below. The code is needed ASAP so I'm giving it a level of difficult at 250 points.

In the DB, this is what's being imported (with quotations)
"Company1" | "First1" | "Last1" | "Address1"
"Company2" | "First2" | "Last2" | "Address2"

But, this is what I want (without quotations)
Company1 | First1 | Last1 | Address1
Company2 | First2 | Last2 | Address2

Here's my code
Start Code:
<%@ Language=VBScript %>
<% pageTitle = "Bulk Insert Page" %>
<!--#include file="adovbs.inc"-->
<!--#include file="db.asp"-->

<%
dim Conn
dim filePath

filePath = "C:\cold.xls"

set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConString
   
Conn.execute("bulk insert Cold from '"&filePath&"' WITH (FIRSTROW = 2, FIELDTERMINATOR = ',', ROWTERMINATOR = '\n')")

Conn.close
set Conn = nothing
%>

<html>
<title>Bulk Insert Page</title>

<body>
Text File Imported
</body>
</html>

End of Code
0
Comment
Question by:Patriotec
  • 3
  • 2
7 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17792230
>>I need to remove the quotation marks (the text qualifier) when importing data from the text file (.csv or .xls file) using ASP.<<
It can't be done.  Either use DTS or import into a staging table and remove them form there.
0
 
LVL 1

Author Comment

by:Patriotec
ID: 17792349
I meant a web based page, I believe the File Sytem Object can open the file and replace the quotation marks with nothing and then have the corrected info imported into the table or an array that can parse through the file. Just not sure on how this can be done using either method.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17793246
>>I believe the File Sytem Object can open the file and replace the quotation marks with nothing and then have the corrected info imported into the table or an array that can parse through the file<<
That is correct, you can cycle through using the File System object.  However, this does not seem a very efficient way of doing it and further since it is no longer an MS SQL Server question, you should post in a more appropriate Topic Area such as:
http://www.experts-exchange.com/Web/Web_Languages/ASP/
0
 
LVL 1

Author Comment

by:Patriotec
ID: 17797687
ok, how can I use SQL to use DTS from ASP. From what I've read, the DTS can be saved as a stored procedure which I could execute from ASP.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 250 total points
ID: 17797798
>>From what I've read, the DTS can be saved as a stored procedure which I could execute from ASP.<<
No, a DTS package cannot be saved as a stored procedure.  Here is how you can execute DTS from ASP
Execute a package from Active Server Pages (ASP)
http://www.sqldts.com/?207
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now