0
這是我冗長的SQL代碼。我基本上試圖將數據庫信息首先從每月,每日和每年費率轉換爲每小時。然後將此小時數轉換爲美元,如果它尚未。在另一個計算中使用產品 - SQL select語句
到目前爲止,我已將兌換率轉換爲「兌換率」,但在轉換爲美元時如何使用此新兌換率?即在:
WHEN wo.currency = 'GBP' 然後(wo.avg_rate * 1.66)
我不能改變wo.avg_rate要麼wo.converted_rate,x.converted_rate, 「轉化率,」 或「轉化率。'我怎樣才能做到這一點 ?
SELECT
x.work_order_ref as 'Work Order Reference'
,x.buyer_code as 'Buyer Code'
,x.submit_time as 'Work Order Submit Time'
,x.rate_unit_for_spend_calc as 'UOM'
,x.avg_rate as 'ST Rate'
,x.converted_rate as 'Converted Rate'
,x.currency as 'Currency'
,x.converted_amount AS 'Converted Amount'
,jp.title AS 'JP Title'
,lbt.name AS 'Labor Type'
,jp.max_distribution_level AS 'Max Distr Level'
,si.city AS 'City'
,si.state_province as 'State'
,si.country AS 'Country'
,ctg.name AS 'Category'
,count(jpd.supplier_code) as 'Suppliers'
from
(select
wo.work_order_ref
,wo.buyer_code
,wo.submit_time
,wo.rate_unit_for_spend_calc
,"converted_rate" =
CASE
WHEN wo.rate_unit_for_spend_calc='Hr' then wo.avg_rate
WHEN wo.rate_unit_for_spend_calc='MO' then (wo.avg_rate/173.333)
WHEN wo.rate_unit_for_spend_calc='Day' then (wo.avg_rate/8)
WHEN wo.rate_unit_for_spend_calc='Yr' then (wo.avg_rate/2080)
END
,wo.avg_rate
,wo.currency
,wo.job_posting_id
,wo.site_id
,wo.worker_id
,wo.uploaded_flag
,wo.sequence
,"converted_amount" =
CASE
WHEN wo.currency='USD' then (wo.avg_rate)
WHEN wo.currency='GBP' then (wo.avg_rate*1.66)
WHEN wo.currency='SEK' then (wo.avg_rate*0.14)
WHEN wo.currency='EUR' then (wo.avg_rate*1.31)
WHEN wo.currency='CAD' then (wo.avg_rate*0.92)
WHEN wo.currency='AUD' then (wo.avg_rate*0.93)
WHEN wo.currency='INR' then (wo.avg_rate*0.017)
WHEN wo.currency='MXN' then (wo.avg_rate*0.076)
WHEN wo.currency='COP' then (wo.avg_rate*0.00052)
WHEN wo.currency='BRL' then (wo.avg_rate*0.44)
WHEN wo.currency='MYR' then (wo.avg_rate*0.32)
WHEN wo.currency='CNY' then (wo.avg_rate*0.16)
WHEN wo.currency='RON' then (wo.avg_rate*0.3)
WHEN wo.currency='CZK' then (wo.avg_rate*0.047)
WHEN wo.currency='SGD' then (wo.avg_rate*0.8)
WHEN wo.currency='PLN' then (wo.avg_rate*0.31)
WHEN wo.currency='JPY' then (wo.avg_rate*0.0096)
WHEN wo.currency='NZD' then (wo.avg_rate*0.84)
WHEN wo.currency='CHF' then (wo.avg_rate*1.09)
--ELSE (wo.avg_rate*x.conversion_factor)
END
from work_order wo(nolock)) as x
...
如果它使它更好地爲我發佈完整的代碼和/或什麼我得到的,我能做到這一點。
目前還不清楚我是什麼問題是。 「你的意思是」無法將wo.avg_rate更改爲wo.converted_rate,x.converted_rate,「轉化率」或「轉化率」。 ? – 2014-09-02 20:57:08
爲了您未來的理智,請將轉換率放入表格中。 – Laurence 2014-09-02 21:13:53
不太清楚你的想法,但它似乎是一個壞方法。更好地嘗試功能,它提供了更多的靈活性。正如@勞雷斯所說的那樣,使用匯率換算表。 – 2014-09-02 21:17:22