创建动态存储过程

USE [SapAllData]
GO

CREATE proc [dbo].[p_cashflow_c]
(
@dbname varchar(50) ,
@stime varchar(10) ,
@etime varchar(10)
)

as
declare @stimeb varchar(10),
@stimec varchar(10)
set @stimeb=(select dateadd(ms,-3,DATEADD(mm,DATEDIFF(mm,0,@stime),0)))
set @stimec=(select convert(nvarchar(20),year(@stime)-1)+’-12-31’)

begin
SET NOCOUNT ON
DECLARE @sql nvarchar(max)
set @sql=

select
sum(case when t1.refdate <=’’’+@stimeb+’’‘then t0.Debit-t0.Credit else 0 end ) as zongjis,
sum(case when t1.refdate <=’’’+@stimec+’’‘then t0.Debit-t0.Credit else 0 end ) as zongjie
from ‘+’ ’ +@dbname+’…JDT1 t0
inner join ‘+’ ’ +@dbname+’…OJDT t1 on t1.TransId=t0.TransId
where t0.Account like ‘‘1001%’’ or t0.Account like ‘‘1002%’’ or t0.Account like ‘‘1003%’’


exec sp_executesql @sql

end
GO

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值