两种不同的操作在不同情况下sql表的功能

时间:2018-02-08 16:45:00

标签: sql differential-equations operation table-functions

我想编写一个功能,可以看到客户花了多少时间而无需向卖家支付费用。我的问题是我有点困惑,因为这是已编程的功能:

ALTER function [dbo].[bal_cli](@date date, @diff1 int,@diff2 int) returns @table1
table 
(
  solde float,
  cpt char(20)
)as

begin

insert into @table1(solde,cpt)
SELECT         SUM(a.ECRDEBIT-a.ECRCREDIT) AS solde,a.CPTCODE
  FROM            dbo.ECRITURES AS a , dbo.ECRITURES AS b
  WHERE      (a.JORID = '7' or a.JORID = '10' or a.JORID = '22' or a.JORID = '15' or a.JORID = '16' or a.JORID ='5' or a.JORID = '38' or a.JORID = '45' or a.JORID = '12' or a.JORID = '17' or a.JORID = '44' or a.JORID = '18' or a.JORID = '8' or a.JORID = '9') AND (a.ECRISMARQUE <> 'O') AND (a.CPTCODE LIKE '3421%') and 
                           ( DATEDIFF(day, a.ECRDATEEFFET, @date) >= @diff1 and  DATEDIFF(day, a.ECRDATEEFFET, @date) < @diff2) and (YEAR(a.ECRDATEEFFET) = YEAR(@date)) 

  GROUP BY a.CPTCODE

return;
end;

我的问题是我想让JORID用ECRDATEEFFET计算差异音符但用ECRLIBELLE计算。

0 个答案:

没有答案