• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

SQL query to Text file via VBA

I need help with  a VBA script that pulls data from sql and inserts into a text file and will also be padding 80bytes on each record. Please help with any ideas .
0
valentinemhlanga
Asked:
valentinemhlanga
  • 3
  • 3
  • 2
3 Solutions
 
Michael FowlerSolutions ConsultantCommented:
Here are some articles to get you started

Here is a step by step guide from Microsoft on importing data from SQL Server to Excel
http://support.microsoft.com/kb/306125

and here is a guide to exporting to a text file
http://www.cpearson.com/excel/ImpText.aspx

Lastly what sort of padding do you want to attach to the file and what is the goal of this?
0
 
valentinemhlangaAuthor Commented:
@Michael74 , I am trying to create a file  in Bank of America file format, they need each record 80 bytes padded , numeric fields should be justified and 0 filled . Alpha numeric fields should be left justified and filled with spaces and all Alpha characters must be uppercase

Thank your for your  help
0
 
SimonCommented:
Do you have a complete specification for the required format?

Can you supply some dummy records that you'd like output in the format?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Michael FowlerSolutions ConsultantCommented:
This should not be hard to do but as noted by @SimonAdept we will need exact specifications to do it. eg

How large should a field be so that the appropriate number of zeros or spaces can be added and what sort of padding needs to be added eg whitespace

To start with I would recommend that you look at exporting the data to a worksheet from SQL Server using the example I provided. Note: You do not need VBA to do this https://support.office.com/en-in/article/Connect-to-import-SQL-Server-data-0f3d2e8f-7d94-4ded-baa6-3b0df183ff98

Once you have this you can sanitise the doc to give an example file to work with. If you are having any issue with just let us know
0
 
valentinemhlangaAuthor Commented:
Thank you all for responding , the input data from SQL  would look something like this

IDNumber              ReportID      ReportName                         Amount      EMPLOYEE
########2154      20              Testing Report Submission         +25.00          436196
########2154      28               General Expense                              +29.00           233568

and the output file should look like the doc attatched Starting on the column where it says P70.  I would like to use SSIS Script task to create this file instead of using excel.
Please do let me know if you need more info regarding this
0
 
SimonCommented:
>and the output file should look like the doc attatched

There was no doc attached!

I also note that your two example lines don't share a common format (when pasted to a text editor with a monospace font).

This really needs to be specificied excactly to work successfully.
0
 
valentinemhlangaAuthor Commented:
I've requested that this question be deleted for the following reason:

n/a
0
 
Michael FowlerSolutions ConsultantCommented:
@valentinemhlanga

Not sure why you have asked to have this deleted as n/a

We are happy to help with your request but unfortunately to create an output in a specific format we need to have exact specs on the format along with some sample data. Given this information the experts on this site can create a script which will meet your needs.

To give you an idea of what is needed

IDNumber
column: 18 characters, left aligned
12 numeric characters, padded with zeros as required

ReportID
column: 18 characters, center aligned
numeric characters, no zero padding

This sort of detail is required regardless of the method used to generate the file
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now