Solved

SQL query  to Text file via VBA

Posted on 2015-01-13
8
242 Views
Last Modified: 2015-01-14
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
Comment
Question by:valentinemhlanga
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 23

Assisted Solution

by:Michael Fowler
Michael Fowler earned 500 total points
ID: 40547687
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
 

Author Comment

by:valentinemhlanga
ID: 40547704
@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
 
LVL 18

Expert Comment

by:Simon
ID: 40547750
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 23

Assisted Solution

by:Michael Fowler
Michael Fowler earned 500 total points
ID: 40547797
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
 

Author Comment

by:valentinemhlanga
ID: 40548100
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
 
LVL 18

Expert Comment

by:Simon
ID: 40549405
>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
 

Author Comment

by:valentinemhlanga
ID: 40550261
I've requested that this question be deleted for the following reason:

n/a
0
 
LVL 23

Accepted Solution

by:
Michael Fowler earned 500 total points
ID: 40550014
@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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

687 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