Hi everybody,
I need some help on calculated values in my database design.
I'm creating an accounting / business management application with the
usual modules like A/R, A/P, Inventory, etc.
I don't know how to handle calculated values in fields like "Customer
Balance", "Inventory Item Qty on Hand", "Inventory Item Qty Last cost"
and other similar.
I don't want to create fields in the database to store these values
but I want to create them on the fly instead. Another thing I prefer
to do is use code in my application (vb.net) not T-SQL to do this
(stored procedure or views), because this way I'm moving business
logic into SQL; so far all the logic is located in a Business Rules
DLL.
My question is how can I do that and at the same time achieve "easy"
joins.
For example:
Every time I retrieve some customer's info I need his balance. Let's
say if my query is:
SELECT CustomerID, CustomerName, Address from Customers
Where CustomerID = ‘xxxxxx'
How can I retrieve the balance, when is calculated from other fields
in other tables, such as Invoices, Credit Memos and Cash Receipts?
I thought to use views and add a join to the above query. Is that good
or bad, performance wise?
What other options I have?
Looking forward for your answer.
Thanks in advanced.
Stefanos 3 2508
Business logic belongs server-side if it involves summarizing data.
Otherwise you might as well use a file-server database like Access. You
don't want to have to retrieve all the data just to add it up at the client.
I can only guess at your table structure and keys but maybe this example
will help:
SELECT C.customerid, C.customername, C.address,
SUM(T.trans_amo unt) AS balance
FROM Customers AS C
JOIN Transactions AS T
ON C.customerid = T.customerid
AND C.customerID = 'xxxxxx'
--
David Portas
SQL Server MVP
--
OOPS! That wasn't very good!
Correction:
SELECT C.customerid, C.customername, C.address,
SUM(T.trans_amo unt) AS balance
FROM Customers AS C
JOIN Transactions AS T
ON C.customerid = T.customerid
AND C.customerID = 'xxxxxx'
GROUP BY C.customerid, C.customername, C.address
--
David Portas
SQL Server MVP
--
David,
Thanks for your reply.
I'm following a "fat-client" implementation.
I agree that business rules belong to the server or in my case the
"fat client".
I don't want to put any logic on the database in the form of sprocs or
similar;
I have enough layers in my design already and I don't want to be tied
in a particular RDBS (currently using MS SQL 2000).
A query like the one you posted is what I've thinking to do, but I
hoped maybe someone has a better solution.
Queries like these are very hard to create in multiple joins.
In your example the table "Transactio ns" isn't enough.
I have to get totals from:
* InvoiceHeader
* CreaditMemoHead er
* CashReceiptsHea der
Imagine now if I have to get the balance in a query that has another
2-3 joins on it.
Stefanos
"David Portas" <RE************ *************** *@acm.org> wrote in message news:<Op******* *************@g iganews.com>... OOPS! That wasn't very good!
Correction:
SELECT C.customerid, C.customername, C.address, SUM(T.trans_amo unt) AS balance FROM Customers AS C JOIN Transactions AS T ON C.customerid = T.customerid AND C.customerID = 'xxxxxx' GROUP BY C.customerid, C.customername, C.address This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stefanos |
last post by:
Hi everybody,
I need some help on calculated values in my database design.
I'm creating an accounting / business management application with the
usual modules like A/R, A/P, Inventory, etc.
I don't know how to handle calculated values in fields like "Customer
Balance", "Inventory Item Qty on Hand", "Inventory Item Qty Last cost"
and other similar.
|
by: Don Vaillancourt |
last post by:
Hello all,
Over the years as I design more database schemas the more I come up with
patterns in database design. The more patterns I recognize the more I
want to try to design some kind of generic design patterns that can be
used and shared amongst many sub-schemas.
For example, the grouping of entities. I may have the following tables:
employee, product and client. These tables have no direct relationship
with each other. But...
|
by: Lane Beneke |
last post by:
All,
New to the list and a relative newbie to PostgreSQL. Please forgive stupid
questions.
Designing an application server for a work order processing (et al)
database. I have a good handle on sequences, referencial integrity, views,
& the basics. What books/documentation would you recommend to learn more
about...
|
by: SJH |
last post by:
I have been given an older database and asked to make upgrades and what not.
One interesting thing I have come across with the database is that it was at
one time set up so one of the tables would hold values that were calcuated
using a form. I have looked at the code for all the text boxes on the
assocatied forms and have yet to figure out how this was done. There were
two values set up this way, one still works and the other one...
|
by: douh |
last post by:
I know that this is not the way, however I need to save certian
calculated values so that they do not change over time, ie. new tax
rates etc. This is for an invoice header and invoice subform. I have a
form myheader and mysub that are linked via a invoice number. mysub
calculates qty * list = extprice. I am summing these into a sum_ext
field in mysub footer. I need to have this value updated into the
myheader invsubtot. I have tried many...
| |
by: MP |
last post by:
Greets,
context: vb6/ado/.mdb/jet 4.0 (no access)/sql
beginning learner, first database, planning stages
(I think the underlying question here is whether to normalize or not to
normalize this one data field - but i'm not sure)
:-)
Background info:
|
by: James Hallam |
last post by:
I have read through all the past topics and couldn't find what I was
after so...
I am looking to store some calculated values (don't flame just yet,
just read on!). I have an piece of code behind a form which calculates
a percentage completion and an expected completion date of a job. I
would like to store this information in a separate table, along with
the actual date the values were calculated.
Whenever a job is completed I can...
|
by: Jim.Mueksch |
last post by:
I am having a problem with using calculated values in a WHERE clause.
My query is below. DB2 gives me this error message: Error: SQL0206N
"APPRAISAL_LESS_PRICE" is not valid in the context where it is used.
SQLSTATE=42703
SELECT DISTINCT S3.OPR_APPLICATION_NR,
S3.APPLICATION_ID,
S3.APPRAISAL_TYPE_CD,
S3.Appraisal_Used_Amount,
S3.RPT_LEVEL2_NR,
|
by: royals |
last post by:
Hello Access gurus,
I am a self-taught Access “developer” and have a ton to learn so please allow me to sound stupid. I am using 2003 on a XP platform.
I manage properties for an organization. At times it is necessary to pay an individual to stay in a house so that it isn’t vacant for an extended period of time. The organization pays the entire utility cost but deducts the individual’s usage cost.
In other words, they receive...
|
by: Gurunath Dhage |
last post by:
Hi All, I’m working on a small project for loan Financial service company. I’m developing a Schedule Entry System . It has a Leasee who takes the loan to purchase products, supplier who supplies products
There are 4 Lease Types monthly, quarterly , half yearly and yearly. There 3 type of Purchase types like local (lease is a local from local state ), interstate and import. This is because each purchase type ie local, interstate and import...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |