declare @sums numeric(15,2) -- 这里必须要写上位数,不然默认为整数declare @cltno varchar(32) declare @feeMoney numeric(15,2)declare cur cursor for sELECT CltNo FROM memberinfo WHERE CltNo NOT IN ('00029098','00027565') -- 定义游标 select @sums = 0.0 open cur --打开游标fetch next from cur into @cltnowhile @@fetch_status = 0 begin SELECT @feeMoney = fee FROM Ns_CMS_Gettable(@cltno,'2015-10-01','22'); select @sums = @sums + @feeMoney;fetch next from cur into @cltnoend close cur -- 关闭游标Deallocate cur -- 删除游标print @sums -- 输出print cast(@sums as varchar(10)) + 'ddddddd' -- 把数字类型转换成字符串
create FUNCTION [dbo].[ns_CMS_getnewfeemoney](@cID int) returns numeric(15,2) as begin declare @sums numeric(15,2) declare @cltno varchar(32) declare @feeMoney numeric(15,2) declare cur cursor for sELECT CltNo FROM memberinfo WHERE CltNo NOT IN ('00029098','00027565') -- 定义游标 begin select @sums = 0.0 open cur fetch next from cur into @cltno while @@fetch_status = 0 begin SELECT @feeMoney = fee FROM Ns_CMS_Gettable(@cltno,'22'); select @sums = @sums + @feeMoney; fetch next from cur into @cltno end close cur -- 关闭游标 Deallocate cur -- 删除游标 end RETURN @sums end总结
以上是内存溢出为你收集整理的SQLserver用游标实现循环 和 简单的量值函数全部内容,希望文章能够帮你解决SQLserver用游标实现循环 和 简单的量值函数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)