SQL根据条件执行不同的语句
有这样的一个SOL语句selectw.WorkloadID,p.ProcessName,F.FlowName,D.District_Name,w.AreaCode,W.S...
有这样的一个SOL语句
select w.WorkloadID,p.ProcessName,F.FlowName,D.District_Name,w.AreaCode,W.SCadastralNumber,W.ECadastralNumber,W.WE_Name,W.W_Name,W.GroupWork,W.STime,W.Days,W.ETime,F.FlowName,F.DayWorks,W.Days,W.Days*F.DayWorks as DayWorks,convert(decimal(18,2),W.GroupWork-(W.Days*F.DayWorks)) as DeductDayW,convert(decimal(18,2),W.GroupWork-(W.Days*F.DayWorks)*P.P_Ratio,2) as Yield
from Workload W left join District D on W.District_ID=D.District_Num
Left join Process p on w.ProcessID=p.ProcessID
left join Flow F on w.FlowID=F.FlowID
我想显示的条件是如果F.FlowID=‘-1’那么convert(decimal(18,2),W.GroupWork-(W.Days*F.DayWorks)*P.P_Ratio,2) as Yield执行这个,如果不等于-1那么就执行这个
convert(decimal(18,2),W.GroupWork-(W.Days*F.DayWorks)*F.F_Ratio,2) as Yield
求大神啊 展开
select w.WorkloadID,p.ProcessName,F.FlowName,D.District_Name,w.AreaCode,W.SCadastralNumber,W.ECadastralNumber,W.WE_Name,W.W_Name,W.GroupWork,W.STime,W.Days,W.ETime,F.FlowName,F.DayWorks,W.Days,W.Days*F.DayWorks as DayWorks,convert(decimal(18,2),W.GroupWork-(W.Days*F.DayWorks)) as DeductDayW,convert(decimal(18,2),W.GroupWork-(W.Days*F.DayWorks)*P.P_Ratio,2) as Yield
from Workload W left join District D on W.District_ID=D.District_Num
Left join Process p on w.ProcessID=p.ProcessID
left join Flow F on w.FlowID=F.FlowID
我想显示的条件是如果F.FlowID=‘-1’那么convert(decimal(18,2),W.GroupWork-(W.Days*F.DayWorks)*P.P_Ratio,2) as Yield执行这个,如果不等于-1那么就执行这个
convert(decimal(18,2),W.GroupWork-(W.Days*F.DayWorks)*F.F_Ratio,2) as Yield
求大神啊 展开
2个回答
展开全部
select w.WorkloadID,
p.ProcessName,
F.FlowName,
D.District_Name,
w.AreaCode,
W.SCadastralNumber,
W.ECadastralNumber,
W.WE_Name,
W.W_Name,
W.GroupWork,
W.STime,
W.Days,
W.ETime,
F.FlowName,
F.DayWorks,
W.Days,
W.Days*F.DayWorks as DayWorks,
convert(decimal(18,2),W.GroupWork-(W.Days*F.DayWorks)) as DeductDayW,
case when F.FlowID='-1' then convert(decimal(18,2),W.GroupWork-(W.Days*F.DayWorks)*P.P_Ratio,2) else convert(decimal(18,2),W.GroupWork-(W.Days*F.DayWorks)*F.F_Ratio,2) end as Yield
from Workload W left join District D on W.District_ID=D.District_Num
Left join Process p on w.ProcessID=p.ProcessID
left join Flow F on w.FlowID=F.FlowID
看看是这个意思吗?
追问
对,就是这个意思,谢谢了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询