473,466 Members | 1,296 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dynamic formulas driven by table

I'm working with a DB design that seems to me to be rather complex.

This is a very slimmed down version of what I'm doing, but I believe it
is enough to get my question resolved.

Here is my layout.

These 4 tables are used to generate a questionaire.

Survey OrderID
========= ==========
SurveyID OrderID
OrderID QuestionGrpID

QGrp Questions
============= =============
QuestionGrpID QuestionID
QuestionID QuestionText
The following two tables are used to calculate a report that is sent to
the customer.

RawData
=========================
OrderID
QuestionID
Value is string but is Cast as decimal for numeric formulas
Metrics
==============================================
QuestionGroupID | ReportText | Formula | MetID
==============================================
2 | % Support Staff of Total | OP21/(OP21+OP22+OP23) | 1

The OP references are questionIDs

Now to calculate the result for the report we programatically parse the
formula creating a temp table (table name = Temp & orderID & _ &
QuestionID) with OrderID and OPxx as the field names. We create one
table for each question.

We then use dynamic SQL again to calculate the result using the above
formula

SELECT OP21/(OP21+OP22+OP23) FROM Temp5_21, Temp5_22, Temp5_23 WHERE
Temp5_21.OrderID = Temp5_22.orderID AND Temp5_22.OrderID =
Temp5_23.OrderID

This select is used to create a single table of calculated values.
This table is in turn used to tell the customer how they compare to
other customers. Percentile, Mean, Median, Std Dev, and a few others. I
don't claim this part of the project, but I'm not sure how I might have
done it, had it been assigned to me.

MY PROBLEM!!!
Sometimes a 0 is valid data and is the denominator of a devision
calculation. Since this is so dynamic and it might be difficult to
determine when division is used. I need a way to default divide by 0
execptions to NULL. This DB is on a hosted server.
Thanks for bearing with me,

Greg Kelley

Jul 23 '05 #1
2 4570

"yzarc" <yz******@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
I'm working with a DB design that seems to me to be rather complex.

This is a very slimmed down version of what I'm doing, but I believe it
is enough to get my question resolved.

Here is my layout.

These 4 tables are used to generate a questionaire.

Survey OrderID
========= ==========
SurveyID OrderID
OrderID QuestionGrpID

QGrp Questions
============= =============
QuestionGrpID QuestionID
QuestionID QuestionText
The following two tables are used to calculate a report that is sent to
the customer.

RawData
=========================
OrderID
QuestionID
Value is string but is Cast as decimal for numeric formulas
Metrics
==============================================
QuestionGroupID | ReportText | Formula | MetID
==============================================
2 | % Support Staff of Total | OP21/(OP21+OP22+OP23) | 1

The OP references are questionIDs

Now to calculate the result for the report we programatically parse the
formula creating a temp table (table name = Temp & orderID & _ &
QuestionID) with OrderID and OPxx as the field names. We create one
table for each question.

We then use dynamic SQL again to calculate the result using the above
formula

SELECT OP21/(OP21+OP22+OP23) FROM Temp5_21, Temp5_22, Temp5_23 WHERE
Temp5_21.OrderID = Temp5_22.orderID AND Temp5_22.OrderID =
Temp5_23.OrderID

This select is used to create a single table of calculated values.
This table is in turn used to tell the customer how they compare to
other customers. Percentile, Mean, Median, Std Dev, and a few others. I
don't claim this part of the project, but I'm not sure how I might have
done it, had it been assigned to me.

MY PROBLEM!!!
Sometimes a 0 is valid data and is the denominator of a devision
calculation. Since this is so dynamic and it might be difficult to
determine when division is used. I need a way to default divide by 0
execptions to NULL. This DB is on a hosted server.
Thanks for bearing with me,

Greg Kelley


Check out SET ANSI_WARNINGS, SET ARITHABORT and "Behavior if Both ARITHABORT
and ARITHIGNORE Are Set ON" in Books Online - this will do what you want.
But, it's not a recommended solution, because it means you can't use
features like distributed queries and indexed views, and it may create
problems with other code.

Alternatively, you might be able to store your formulae with a NULLIF around
the divisor:

OP21/NULLIF((OP21+OP22+OP23), 0)

If that's not possible, and you can't be sure what the divisor will be, then
you would probably have to look at solving it outside the database, either
by parsing the formulae to insert a NULLIF dynamically, or perhaps by doing
some calculations externally.

Simon
Jul 23 '05 #2
Thanks,
I appreciate the reply. I'm using a fairly basic parser to divide the
OP codes out and creat the table. I may look at tagging the OP codes so
that I can strip anything out that is not an OP code for creating my
tables.

Thanks again,
Greg

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: LineVoltageHalogen | last post by:
Greeting All, I have a stored proc that dynamically truncates all the tables in my databases. I use a cursor and some dynamic sql for this: ...... create cursor Loop through sysobjects and...
3
by: daveland | last post by:
I am working on some JavaScript that dynamically adds rows to a table in response to a button click. A new row does appear on the screen when the button is clicked. However, that table to which a...
1
by: Eugene | last post by:
In a DB2 V8.1 FP4 database I am trying to create a table SQL UDF that is to return a contents of a temporary table with in this UDF: create function getitemdata(pint int) returns table (...
16
by: pukivruki | last post by:
hi, I wish to create a temporary table who's name is dynamic based on the argument. ALTER PROCEDURE . @PID1 VARCHAR(50), @PID2 VARCHAR(50), @TICKET VARCHAR(20)
2
by: philin007 | last post by:
Hi Guys, Could any one help me out with codes to add rows to a table. Well I kinda of got the codes from the following site (http://www.interviewboard.com/DHTMLSamples/DHTMLGridSample.htm) the...
9
by: CoreyWhite | last post by:
I have a vision for webservers, like apache, which drive websites online. Html and PHP are basically just templates that webservers *USE*. If we want to be real geniuses then we need to code our...
0
by: senthilnathan1985 | last post by:
Hi to everybody i implementing asp.net in my project with sql server 2005 i have one doubt in creating dynamic table in design page In php this is the code for creating table rows and...
3
by: saneman | last post by:
std::vector<intv creates a dynamic array where its possible to insert new elements without doing any preallocation. But how about a dynamic double array? I would like to have something like: ...
5
by: madhanrajesh210002 | last post by:
I'm trying to calculate dynamic formula value for dynamic inputs, that is user inputs and formulla all will be given by user, i tried in php, but failed , codes as follows, $a=10; //$a -...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
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...
0
agi2029
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,...
0
isladogs
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.