Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2016
    Posts
    2

    Question Unanswered: Formulas in Tables

    hi, i'm trying to solve an old problem with a software that we are developing, i have a initial data and a lot of formulas to calculate another lot of data with this initial one. the real question is.

    1.- what is the best way of to do this action?.

    2.- can i have a table where the formulas are stored and then execute some store procedure to calculate the rest?

    3.- can this formulas has parameters ( Like Countries, Dates, etc) to know wich formula should the system use?

    4.- Is MSQL Server the best choice? or informix, Mysql?

    Thanks a lot for the advice

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,445
    Provided Answers: 12
    Your question is incredibly broad; but I'll try point you down a couple of avenues to investigate:

    Calculated columns:
    Code:
    CREATE TABLE foo (
       a int
     , b int
     , c int
     , d AS (a + b + c)
    );
    Using views to encapsulate calculations:
    Code:
    CREATE VIEW bar
      AS
    SELECT a
         , b
         , c
         , (a + b + c) AS d
    FROM   foo
    ;
    Conditional calculations:
    Code:
    CREATE VIEW foo_bar
      AS
    SELECT a
         , b
         , c
         , CASE country_code
             WHEN 'us' THEN (a + b + c)
             WHEN 'ca' THEN (a * b - c)
             WHEN 'gb' THEN (b - a)
             WHEN 'it' THEN (a - b / c)
             ELSE (a * c)
           END As e
    FROM   foo
    ;
    George
    Home | Blog

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •