Monday 15 July 2013

sql server 2008 - SQL calculated column with case statement and table join -


OK, I've digged some web sites and do not think how this situation works or even if it's possible .

I am using SQL Server 2008 and there is a calculated column where I am trying to understand some values ​​about foreign currency exchange rates.

While running in the same table can be easy for a long time, I want to use the correct solution that includes two separate tables

table T1 keeps a log of the transaction. Table t2 contains basic information for a given currency, two tables can be added using the currencyCode attribute.

The sticky part comes with currency-dependent calculations. Currently calculating only CR1 CR3 CR3 CR4 < / Code>, but in the future the more currencies are added, the different capacities are different for the new currencies, so ideally, a new row is passed to t2 and A bit flag will be added to ( flagCurrencyCalc ) which is not used or used in alternative calculations Has been specified.

Then the current formula looks like something:

  (when [currencycode] = 'CR1' or [currencyCode] = 'CR2' or [currencyCode] = 'CR3' Or [currencyCode] = 'CR4' again (Formula 1) and (Formula 2) end) As you can see, I have to go manually and with new currency. The format must be changed by adding another or statement. .  

Is it possible that:

(when t2.flagCurrencyCalc = true ) for the currency code given in a record then in T1 Found (formula1) second (formula 2) end)

???

You can not see directly in another computed column from another table (see).

Here are some options.

, 'CR4'), you can use a view:

  Select view vw_tablename t * (When the matter is in currency (Select Currency from ListOfCurrencies from where.) Then (formula1) second (formula 2) end);   

You can define the function to check currency.

No comments:

Post a Comment