?
Solved

Export Flat File from MS SQL

Posted on 2004-10-12
2
Medium Priority
?
1,298 Views
Last Modified: 2012-06-27
I got a job that request me to submit a flat file to a bank. this flat file using the EDIFactoring format for IDEAL Account Receivable System. and the file must have a fixed format, eg  to start a record:

Position 1-5    RecordID   Lenth 5   Value='ABC01'
Position 6-19  Filter         Lenth 14 Value is space

I only know a flat file is a one dimemsion data file can be stored as a .txt file.

May I know if it's possible to use asp to generate such a file? If possible how to ? Thank you very much!!
0
Comment
Question by:shuwenjing
[X]
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
2 Comments
 
LVL 2

Expert Comment

by:Tdl
ID: 12295678
Hi, it sure is possible to use asp for it, you can also use most other languages like vb, c++ and this can even be done directly in the database. But what are your requirements? Do you have to do it in asp? Or would you like to do it in asp because you know asp? Are you allowed to do it in the database?

Marc
0
 
LVL 26

Accepted Solution

by:
Alan Warren earned 1000 total points
ID: 12296391
Hi shuwenjing

You will need something like this to persist a  recordset as a text file using ASP
This example connects to Northwind sql catalog and pulls 2 fields from the employees table
and space pads the fields then uses the FileSystemObject to create a temporary file to persist the data.



Alan

<%@ Language=VBScript %>

<HTML>
<HEAD>
</HEAD>
<BODY>

<P>&nbsp;</P>

</BODY>
</HTML>
    <%
     
      Dim objConn                   ' Database Connection
      dim sDataConnect              ' ADO SQL connect string
      Dim objRS                     ' ADO Recordset Object
      Dim objFso                    ' Scripting.FileSystem object
      Dim strSQL
      Dim strTemp
      Dim objFile                   ' Temporary file
     
      ' Instantiate a database connection
      Set objConn = Server.CreateObject("ADODB.Connection")

      ' Create an ADO connect string
      sDataConnect = adoConnectSQL("password", "sa", "NorthWind", "(local)")
     
      ' Open a database connection
      objConn.Open sDataConnect
     
      ' Build your sql string
      strSQL = "SELECT EmployeeID, LastName FROM dbo.Employees"
     
      ' Instantiate your recordset object
      Set objRs = Server.CreateObject("ADODB.Recordset")
     
      ' Open the recordset
      objRS.Open strSQL, objConn,3,3
     
      ' banking files have fields padded with space characters
      ' space chars differ from empty space "   "
     
      ' either left or right padding is specified
        ' Example of left padding
        ' Space(5-Len(.Fields("EmployeeID"))) & .Fields("EmployeeID")
        ' Space(14-Len(.Fields("LastName"))) & .Fields("LastName")
       
        ' Example of Right padding
        ' .Fields("EmployeeID") & Space(5-Len(.Fields("EmployeeID")))
        ' .Fields("LastName") & Space(14-Len(.Fields("LastName")))
       
        ' output like "2    Fuller        "
      With objRs
        While Not .EOF
          strTemp = strTemp & .Fields("EmployeeID") & Space(5-Len(.Fields("EmployeeID")))
          strTemp = strTemp & .Fields("LastName") & Space(14-Len(.Fields("LastName")))
          strTemp = strTemp & vbcrlf
          .MoveNext
        Wend
       
        ' replace vblf with break so I can view the output in browser
        ' Response.Write(Replace(strTemp,vblf,"<br />"))
       
        .Close
      End With
      objConn.Close
      Set objConn = Nothing
      Set objRs = Nothing
     
      ' Write strTemp to File
      Set objFile = CreateTempFile
      objFile.Write(strTemp)
      objFile.Close
      Set objFile = nothing
     
      %>
     
      <%
     
        Function CreateTempFile
           Dim tfolder, tname, tfile, fso
           set fso = Server.CreateObject("Scripting.FileSystemObject")
           Const TemporaryFolder = 2
           Set tfolder = fso.GetSpecialFolder(TemporaryFolder)
           tname = fso.GetTempName
           Set tfile = tfolder.CreateTextFile(tname)
           Set CreateTempFile = tfile
           Response.Write("File saved to: " & tfolder & "\" & tname )
        End Function

     
        Public Function adoConnectSQL(psPassword, psUser, psCatalog, psDataSource)

          ' Returns SQLOLEDB ADO connect string
          ' Uses SQL Server security
          ' web-farm server expects: user = 'anonymous' and password=""
          ' anonymous user has very limited rights

          Dim sProvider, sPassword, sPersist, sUser, sCatalog, sDataSource

          sProvider = "Provider=SQLOLEDB.1;"
          sPassword = "Password=" & psPassword & ";"
          sPersist = "Persist Security Info=True;"
          sUser = "User ID=" & psUser & ";"
          sCatalog = "Initial Catalog=" & psCatalog & ";"
          sDataSource = "Data Source=" & psDataSource
          adoConnectSQL = sProvider & sPassword & sPersist & sUser & sCatalog & sDataSource

        End Function
     
      %>
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

765 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