Solved

SQL query  to Text file via VBA

Posted on 2015-01-13
8
208 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
Comment Utility
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
Comment Utility
@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:SimonAdept
Comment Utility
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
 
LVL 23

Assisted Solution

by:Michael74
Michael74 earned 500 total points
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:valentinemhlanga
Comment Utility
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:SimonAdept
Comment Utility
>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
Comment Utility
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
Comment Utility
@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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

11 Experts available now in Live!

Get 1:1 Help Now