Solved

SQL query  to Text file via VBA

Posted on 2015-01-13
8
216 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
  • 3
  • 3
  • 2
8 Comments
 
LVL 23

Assisted Solution

by:Michael74
Michael74 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 23

Assisted Solution

by:Michael74
Michael74 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:
Michael74 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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