写了个存储过程,但是遇到变量与SQL语句连接的问题,导致不能执行,恳求大家帮忙!!!!!
CREATE PROCEDURE dbo.InvSum_Prc
(
@invChkMainFid numeric(18,0) ,
@fdept numeric(18,0),
@fcustomer numeric(18,0),
@fmarket numeric(18,0),
@finvTime DateTime, --盘点日期
@fpcode varchar(20), --产品大类编码
@qSql varchar(50), --查询条件
@fzt numeric(9,0), --帐套
@find numeric(9,0), --产业
@xed numeric(9,0)
)
AS
begin
SELECT FPRODUCT,PRODUCTNAME,SUM(FSUM) AS FACVAL, 0 as FADJVAL,'' as FADJWHYS FROM (
select b.fproduct,b.productname,sum(b.fnum) as fsum from outorder_list_static a left join
outorder_de_static b on a.fid=b.fid inner join zt@fztsysinfo.DBO.PRODUCT_LIST c on c.fid=b.fproduct
and c.xed=1 and c.fend=1 and c.fcode like @fpcode where a.xed=1 and a.findustry=@find and a.fdept=@fdept
and a.fcustomer=@fcustomer and a.etime between @finvTime and getdate() group by b.fproduct,b.productname
union all
select a.fproduct,a.fproductname,sum(-a.fqty) as fsum from tblsales a inner join
zt@fztsysinfo.DBO.PRODUCT_LIST c on c.fid=a.fproduct and c.xed=1 and c.fend=1
and c.fcode like @fpcode where a.xed=1 and a.fbrand='普多' and a.fdept=@fdept and a.fmarket=@fmarket
and a.fdate between @fInvTime and getdate() group by a.fproduct,a.fproductname
union all
SELECT a.fproduct,a.fproductname,a.finvsum as fsum FROM InvCheck_Static a
inner join zt@fztsysinfo.DBO.PRODUCT_LIST c on c.fid=a.fproduct and c.xed=1 and c.fend=1 and c.fcode like @fpcode
WHERE a.XED=1 AND a.FMARKET=@fmarket AND fopmon=(datepart(month,getdate())-1)
union all
select b.fproduct,b.fproductname, sum(b.fadjval) as fsum from invcheck_main
a inner join invcheck_detail b on a.fid=b.forderid and a.xed=1 and a.fmarket=@fmarket
and a.finvtime between @finvTime and datepart(year,getdate())+'-'+datepart(month,getdate())+'-01'
inner join zt@fztsysinfo.DBO.PRODUCT_LIST c on c.fid=b.fproduct and c.xed=1
and c.fend=1 and c.fcode like @fpcode where a.fid=@invChkMainFid and a.xed=@xed
group by b.fproduct,b.fproductname
) aaa group by fproduct,productname
end
RETURN
GO
请大家注意
zt@fztsysinfo.DBO.PRODUCT_LIST
我的目的是根据 @fzt 来 组成 库的名称
比如 zt1sysinfo.dbo.product_list
但调试通不过,使用 zt+''+@fzt+''+sysinfo.dbo.product_list 也不行