【发布时间】:2015-01-13 10:57:57
【问题描述】:
我想创建一个包含两个新列 SC 和 NC 的视图。
我想编写一个比较 country1 和 Supplier Country 的逻辑,如果匹配,那么我想比较 MOQ。如果匹配,那么我希望将相应 MOQ 的成本存储在 View as NC, SC
这种方法是否适合这样做。
最多有 3 个国家,5 个起订量,3 个供应商国家,3 个供应商起订量。
create view viewCountry as
select dbo.SCN_Vw_ProjectDetailsReport_Revision.*,'' as SC, '' as NC,
case
when
country1=supplier_country1
then
(
case
when
lot_size=negotiated_lot_size then lot_size1_1 as SC, Negotiated_cost as NC
when
moq2=negotiated_lot_size then lot_size2_1 as SC, Negotiated_cost as NC
when
moq3=negotiated_lot_size then lot_size5_1 as SC, Negotiated_cost as NC
when
moq4=negotiated_lot_size then lot_size10_1 as SC, Negotiated_cost as NC
when
moq5=negotiated_lot_size then lot_size25_1 as SC, Negotiated_cost as NC
else NULL as SC, NULL as NC
) end as SC,NC
when
country1=supplier_country2
then
(
case
when
lot_size=negotiated_lot_size2 then lot_size1_1 as SC, Negotiated_cost2 as NC
when
moq2=negotiated_lot_size2 then lot_size2_1 as SC, Negotiated_cost2 as NC
when
moq3=negotiated_lot_size2 then lot_size5_1 as SC, Negotiated_cost2 as NC
when
moq4=negotiated_lot_size2 then lot_size10_1 as SC, Negotiated_cost2 as NC
when
moq5=negotiated_lot_size2 then lot_size25_1 as SC, Negotiated_cost2 as NC
else NULL as SC, NULL as NC
)
when
country3=supplier_country3
then
(
case
when
lot_size=negotiated_lot_size3 then lot_size1_1 as SC, Negotiated_cost3 as NC
when
moq2=negotiated_lot_size3 then lot_size2_1 as SC, Negotiated_cost3 as NC
when
moq3=negotiated_lot_size3 then lot_size5_1 as SC, Negotiated_cost3 as NC
when
moq4=negotiated_lot_size3 then lot_size10_1 as SC, Negotiated_cost3 as NC
when
moq5=negotiated_lot_size3 then lot_size25_1 as SC, Negotiated_cost3 as NC
else NULL as SC, NULL as NC
)
from SCN_Vw_ProjectDetailsReport_Revision
【问题讨论】:
标签: sql-server sql-server-2008 views