if exists (select * from sysobjects where name ='proc_chuikuan')
drop procedure proc_chuikuan
GO
create procedure proc_chuikuan
As
declare @n int ,@a int,@b int
--查出系统时间是否在月末
select @n =day(dateadd(mm,1,getdate())-day(getdate()))--查询本月的天数
select @a=datepart(day,getdate())--查询当前系统是本月几号
set @b=@n-@a--当前日期与月末有几天
if (@b<4)--如果当前日与月底少于四天,就被判定为月末,并查询出相关余额不足100的客户信息,进行催款……
select b.customerName,b.telephone,a.balance from dbo.cards as a inner join dbo.Users as b on a.customerID =b.customerID where a.balance<100
else
print '没有相关信息'
GO
--------测试数据-----------
exec proc_chuikuan