日期:2014-05-16  浏览次数:20567 次

请问下面的存储过程错在哪呢?

CREATE  PROCEDURE Cx_indexJl

 @TxTs int,@Bm nVarchar(20)  
WITH ENCRYPTION 
AS
Declare @Date Datetime,@cou1 int,@cou2 int

Set @Date=Convert(Varchar(10),GetDate(),120)

select @Cou1=Count(*) from CkInfo a inner join Login b on a.Lrczy=b.CzyName where b.czyBm=@Bm and ShenHe=1 and
 day(@Date)<>LastJxDate and YeMoney>0 and
 (BeginDate+4<GetDate() and day(BeginDate)=day(@Date))

select @Cou2=Count(A.id) from DkInfo a,hkjhMan b inner join Login c on a.Lrczy=c.CzyName Where c.czyBm=@Bm and
 a.pzh=b.h_dh and a.YeMoney>0 and a.ShenHe=1 and (b.h_LxMoney>0 or b.h_Money>0) and b.h_hkQk='未还款'
 and b.h_date between @Date and Convert(Varchar(10),GetDate()+3,120)

Select @cou1 As JtLxc,@cou2 As StLxc


报下面的错误了

服务器: 消息 207,级别 16,状态 3,过程 Cx_indexJl,行 10
列名 'czyBm' 无效。
服务器: 消息 107,级别 16,状态 1,过程 Cx_indexJl,行 14
列前缀 'a' 与查询中所用的表名或别名不匹配。


但czybm这个字段在login表中是有的。
------解决方案--------------------
可以修改为:

CREATE  PROCEDURE Cx_indexJl

 @TxTs int,@Bm nVarchar(20)  
WITH ENCRYPTION 
AS
Declare @Date Datetime,@cou1 int,@cou2 int

Set @Date=Convert(Varchar(10),GetDate(),120)

select @Cou1=Count(*) from CkInfo a inner join Login b on a.Lrczy=b.CzyName where b.czyBm=@Bm and ShenHe=1 and
 day(@Date)<>LastJxDate and YeMoney>0 and
 (BeginDate+4<GetDate() and day(BeginDate)=day(@Date))

select @Cou2=Count(A.id) from DkInfo a,hkjhMan b,Login c 
Where a.Lrczy=c.CzyName and c.czyBm=@Bm and
 a.pzh=b.h_dh and a.YeMoney>0 and a.ShenHe=1 and (b.h_LxMoney>0 or b.h_Money>0) and b.h_hkQk='未还款'
 and b.h_date between @Date and Convert(Varchar(10),GetDate()+3,120)

Select @cou1 As JtLxc,@cou2 As StLxc

------解决方案--------------------
在有from a,b 这种写法中,后面不能再用 inner join,只能是要么全部改成inner join的方式,要么就是:

from a,b,c where 关联条件
------解决方案--------------------
Login要加个括号,关键字有时候会引起错误