Budget Example for Microsoft Excel and SQL Server
- To show a concept of SaveToDB usage for application development.
- To show a concept of working with normalized database using Microsoft Excel.
- To show a concept of complex screen input forms.
- To show a concept of user INSERT, UPDATE and DELETE procedures generation and usage.
- To show a method of system integration.
The example is fully functional with free SaveToDB Community Edition except BudgetForm and PlanPayments sheets that require SaveToDB Enterprise Edition or trial version.
Free SQL Server 2008/R2 Express Edition can be used also.
This example is included to SaveToDB standalone installer. Example's data stored in SQL Azure.
So, you can try this example right after install.
Also you can download SaveToDB SDK to deploy this example to internal SQL Server or SQL Azure.
There is a database of Payments and Cash Flow reports.
See Payments example.
- To add a feature of plan payments.
- To create a Plan Cash Flow report.
- To create a Plan-Fact Cash Flow report.
- Multi-user work is required.
- Budget system is required...
Our company is not alone that needed the budget system. Definitely there are many ready budget applications.
- Otherwise the required system is very simple and cleared.
We can use current applications as Microsoft Excel with SaveToDB Add-In and SQL Server.
- It is required to design a database, to create some procedures and to implement screen budget form.
- The database will be normalized.
The database will include tables: Item, Company, Account, Manager, Payments and Budget.
- As source payments table is not normalized we will create a new database and will import data with normalization.
- For editing of database tables we will use Microsoft Excel with default SaveToDB edit mode.
- For report control we will use Microsoft Excel with SaveToDB.
- For convenient budget form we will create a special screen form and will create procedures for data changes.
- For access control we will create three schemas: dbo - for developers, xls - for users, etl - for data import/transform operations.
- Create database, schemas, tables, keys and constraints.
- Create Payments import procedure and import payments.
- Create new Cash Flow reports in new database.
- Create edit procedures for plan payments table as it uses foreign keys.
- Create a workbook and add sheet for universal select and edit operations of any table.
- Insert plan payments as fact payments for testing.
- Create required Plan and Plan-Fact Cash Flow reports.
- Design screen Budget Form and create SQL Server procedures for data changes.
Insert plan payments for future period.
- Create a query for the SaveToDB Query List with user database objects.
- Create a result workbook with sheets for all reports, write short help.
- Train users.
- Accept a technology.
- Setup user rights in SQL Server.
- Setup SaveToDB Enterprise Edition for users who will input budget data.
During trial period users can use trial version of SaveToDB.
- Setup SaveToDB Community Edition for other users.
- Publish or email the new workbook.
Creation of Database, Schemas, Tables, Keys and Constraints
Example zip contains full script. As a result we will have the following objects:
Important! Name field of Item, Company, Manager, Account tables should have a unique key.
This field is used to define an ID for Name field from Excel.
Creation Payments Import Procedure and Payments Import
There are many methods for import data to SQL Server.
For example use we will create etl.viewSimplePayment view that outputs payments data and etl.uspUpdatePayment procedure that imports payments with simultaneous normalization.
Using of intermediate etl.viewSimplePayment let's to switch data source or change authentication it the future.
As we can see above the only not existing item, account and company names are inserted.
Payments table is deleted and fully filled during each import. This is simplest way for example goals.
Creation of New Cash Flow Reports in New Database
Stored procedures creation is an ordinary task. As a result we will have following database objects:
- xls.viewPayment - Payments view of our database (not source enSimplePayments)
- dbo.viewCashFlowData - as a data source for stored procedures
Creation of Edit Procedures for Plan Payments Table
Plan Payments table contains foreign keys for items, companies, managers (see topics above).
Our task is using in Excel names of objects not IDs.
To do this we will create a database view with names and INSERT, UPDATE and DELETE procedures with parameters as names. The procedures should correctly determine ID for name.
This is typical task of development using Microsoft Excel and SaveToDB.
SaveToDB contains uspGenerateEditProcedures stored procedure for code generation. Of course, then you can modify the code.
Let's add etl.uspGenerateEditProcedures to database and execute it for code generation in target xls schema for dbo.Budget table:
The procedure will generate codes for four procedures:
Creation of Sheet for Universal Select and Edit Operations of any Table
Let's create new workbook and then connect to enSimpleBudget and select dbo.uspBudget_select procedure.
As a result sheet will contain procedure result, plan payments, and user can select any database object using the Query List.
Pay attention that the Query List not contains xls.uspBudget_insert, xls.uspBudget_update and xls.uspBudget_delete procedures.
By default SaveToDB excludes procedures with _insert, _update and _delete suffixes.
You can see that _select procedure results are editable as the "Save to DB" button is enable.
Insertion of Plan Payments
Now we can insert plan payments using dbo.uspBudget_select Excel table.
The best way is to copy data from source payments, paste it to editable plan payments table and click "Save to DB" button.
This process is shown in Payments example.
Important! Column order of tables is different so use a copy by columns technique.
Creation of Required Plan and Plan-Fact Cash Flow Reports
Report as stored procedure creation is an ordinary development task. As a result database will contain following objects:
Design of Screen Budget Form and Creation of SQL Server Procedures for Data Changes
Budget Form should contain editable month data for required year.
The result form is like this:
To implement this form we should create a select procedure (xls.uspBudgetForm) and three procedures for data changes:
The codes of these procedures are in example zip. The solution is very interesting and beautiful.
Creation of Query for SaveToDB Query List
There are many objects in the database. Some of them should not be visible for end users.
To solve this task we will create xls.viewQueryList view that will output the following results:
As we can see all objects belong to xls schema. Exactly for this schema we will setup end user rights.
As we can see xls.uspBudget_select and xls.uspBudgetForm output results are editable because SQL Server INSERT_PROCEDURE, UPDATE_PROCEDURE and DELETE_PROCEDURE are configured for these objects.
For using the new query on a sheet use "Connect to DB" dialog and select the query.
SaveToDB defines available query lists by field signature, so an application can contain as many query lists as needed.
Result Workbook Creation
The database development is complete.
Now we can create a result workbook for users. We add sheets with reports and forms and write short help.
For end users our application is a native Excel workbook.
Universal database table editor sheet
Editable Plan Payments
Editable Budget Form
Cash Flow Budget
Cash Flow Budget Summary
Cash Flow Summary
Other steps include:
- User training.
- Technology Accept.
- SQL Server user rights setup.
- SaveToDB Enterprise Edition setup for users who will input budget data.
- SaveToDB Community Edition setup for other users.
- New workbook publishing or e-mailing.
- SQL Server and Microsoft Excel with SaveToDB Add-In are suitable for some kinds of corporate applications.
- Microsoft Excel with SaveToDB Add-In is simply customizable for working with normalized databases.
- Screen forms can be complex unlike simple table rows. It is possible to edit any data and send changes to SQL Server.
- INSERT, UPDATE and DELETE procedures are used to change server data.
SaveToDB generates these procedures for database tables automatically.
You can generate these procedures yourself using uspGenerateEditProcedures stored procedure and then modify them.
You can implement these procedures yourself for any complex form.
- Even simple systems can be very useful for users due to integration with other corporate applications.