我遇到错误的情况.....当和使用它不工作显示结果为0但当我使用或它显示结果..... [英] Am Getting Error In Case .....When And Is Used It Is Not Working Showing The Result As 0 But When I Use Or It Is Showing The Result.....

查看:61
本文介绍了我遇到错误的情况.....当和使用它不工作显示结果为0但当我使用或它显示结果.....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

declare @t table
(
Maxmonth int,
startmonth varchar,
Duration int,
endmonth  varchar,
fixedAmount money,
RefferalAmount int
)
insert @t (Maxmonth,startmonth,Duration,endmonth,fixedAmount,RefferalAmount)
select DATEPART(MM,start_date) + fixeddDuration-1,
DATEPART(MM,start_date),
fixeddDuration ,
DATEPART(MM,end_date),
fixedAmount,
case when ( start_date >= Datepart(MM,start_date)) AND ( end_date <= Datepart(MM,end_date))
 then fixedAmount/nullif(fixeddDuration,0)
 ELSE 0
 END
from TC_Project_Referal
where id_tc_projuser = 14
select * from @t





实际上我想计算refferalamount。这里fixedam​​ount是在数据库中从前端给出的..假设1000美元,持续时间是6个月



所以我们需要根据日期计算2-1- 2012年startdate和6-1-2012在这里结束,这段时间是6个月从feb1st到7月1日所以我们需要计算。



1> = 2& ; 1< = 7 ---第1个月 - 这里我们不应该允许,因为开始日期是从feb但是它是jan因此不允许计算



2> = 2& 2< = 7 - 2月



3> = 2& 3< = 7 - 3月



4> = 2& 4< = 7 - 4个月



5> = 2& 5< = 7 - 5月



6> = 2& 6< = 7 - 6月



7> = 2& 7< = 7 - 7月



8> = 2& 8 <= 7 - 7个月---这里不允许计算,因为它是第8个月,但是当你做第8个月时,引用数量将显示为零,因为持续时间仅为6个月,因为我们这样做...它基于用户





我遇到错误.....当和使用时它不是工作显示结果为0,但当我使用OR时显示结果.....



actually i want to calculate the refferalamount . here the fixedamount is given in database from the frontend..lets suppose 1000$ and duration is 6 months

so we need to calculate based on the date 2-1-2012 startdate and 6-1-2012 is enddate here the period of time is 6 months form feb1st to july 1st so we need to calculate.

1>=2 & 1<=7 ---1st month -- here we should not allow because the start date is from feb but it is jan so it is not allowed to calculation

2>=2 & 2<=7 --2nd month

3>=2 & 3<=7 --3rd month

4>=2 & 4<=7 --4th month

5>=2 & 5<=7 --5th month

6>=2 & 6<=7 --6th month

7>=2 & 7<=7 --7th month

8>=2 & 8<=7 --7th month---here calculation is not allowed because it is the 8th month but when you do for 8th month the referralamount will be show as zero because the duration period is only for 6 months as we take like that...it is based on the user


am getting error in case .....when And is used it is not working showing the result as 0 but when i use OR it is showing the result.....

推荐答案

,持续时间为6个月



因此我们需要根据日期2-1-2012 startdate计算,6-1-2012结束这里的时间段是6个月从feb1st到7月1日所以我们需要计算。



1> = 2& 1< = 7 ---第1个月 - 这里我们不应该允许,因为开始日期是从feb但是它是jan因此不允许计算



2> = 2& 2< = 7 - 2月



3> = 2& 3< = 7 - 3月



4> = 2& 4< = 7 - 4个月



5> = 2& 5< = 7 - 5月



6> = 2& 6< = 7 - 6月



7> = 2& 7< = 7 - 7月



8> = 2& 8 <= 7 - 7个月---这里不允许计算,因为它是第8个月,但是当你做第8个月时,引用数量将显示为零,因为持续时间仅为6个月,因为我们这样做...它基于用户





我遇到错误.....当和使用时它不是工作显示结果为0,但当我使用OR时显示结果.....
and duration is 6 months

so we need to calculate based on the date 2-1-2012 startdate and 6-1-2012 is enddate here the period of time is 6 months form feb1st to july 1st so we need to calculate.

1>=2 & 1<=7 ---1st month -- here we should not allow because the start date is from feb but it is jan so it is not allowed to calculation

2>=2 & 2<=7 --2nd month

3>=2 & 3<=7 --3rd month

4>=2 & 4<=7 --4th month

5>=2 & 5<=7 --5th month

6>=2 & 6<=7 --6th month

7>=2 & 7<=7 --7th month

8>=2 & 8<=7 --7th month---here calculation is not allowed because it is the 8th month but when you do for 8th month the referralamount will be show as zero because the duration period is only for 6 months as we take like that...it is based on the user


am getting error in case .....when And is used it is not working showing the result as 0 but when i use OR it is showing the result.....


我无法理解你想在这里实现什么,但你似乎在比较日期和案例陈述中的月份。
I cannot understand what are you trying to achieve here but you seem to be comparing date and month in the case statement.


这篇关于我遇到错误的情况.....当和使用它不工作显示结果为0但当我使用或它显示结果.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆