请看一下我的SQL语句,为什么会出现这样的错误呢?
declare @nd varchar(2),@oldnd varchar(2)
set @nd='03'
set @oldnd=case when len(convert(int,@nd)-1)=1 then '0'+convert(char(1),convert(int,@nd)-1) else convert(char(2),convert(int,@nd)-1) end
select *,isnull((select sum(美元) from hgsj where substring(日期,1,2)=@nd and substring(日期,3,2)=jb.月度 and 进出口=0),0) as 出口当月,
isnull((select sum(美元) from hgsj where substring(日期,1,2)=@nd and substring(日期,3,2)=jb.月度 and 进出口=1),0) as 进口当月,
isnull((select sum(美元) from hgsj where substring(日期,1,2)=@oldnd and substring(日期,3,2)=jb.月度),0) as 进出口同期当月,
isnull((select sum(美元) from hgsj where substring(日期,1,2)=@oldnd and substring(日期,3,2)=jb.月度 and 进出口=0),0) as 出口同期当月,
isnull((select sum(美元) from hgsj where substring(日期,1,2)=@oldnd and substring(日期,3,2)=jb.月度 and 进出口=1),0) as 进口同期当月,
isnull((select sum(美元) from hgsj where substring(日期,1,2)=@nd and substring(日期,3,2)<=jb.月度),0)as 进出口当月累计,
isnull((select sum(美元) from hgsj where substring(日期,1,2)=@nd and substring(日期,3,2)<=jb.月度 and 进出口=0),0) as 出口当月累计,
isnull((select sum(美元) from hgsj where substring(日期,1,2)=@nd and substring(日期,3,2)<=jb.月度 and 进出口=1),0) as 进口当月累计,
isnull((select sum(美元) from hgsj where substring(日期,1,2)=@oldnd and substring(日期,3,2)<=jb.月度),0) as 进出口当月同期累计,
isnull((select sum(美元) from hgsj where substring(日期,1,2)=@oldnd and substring(日期,3,2)<=jb.月度 and 进出口=0),0) as 出口当月同期累计,
isnull((select sum(美元) from hgsj where substring(日期,1,2)=@oldnd and substring(日期,3,2)<=jb.月度 and 进出口=1),0) as 进口当月同期累计
from
(
select sum(美元) as 进出口当月,substring(日期,3,2) as 月度 from hgsj where substring(日期,1,2)=@nd group by substring(日期,3,2)
)jb
提示错误:
服务器: 消息 4408,级别 16,状态 1,行 5
查询和其中的视图或函数超过了 256 个表的限制。
其中hgsj为视图
将子查询去掉几个就没有错误了,
但是去掉了功能就实现不了了,怎么让他没有错误呢