原帖地址:
http://community.csdn.net/Expert/topic/3190/3190686.xml?temp=.6296961
表test中记录:
aa bb
001 50.5
002 60
003 15.4
004 25
005 48
...
输入任一金额,然后在表中查找是否有该金额或几条记录的合计等于该金额.
如:输入25,则要找出004,输入85,则要找出002与004,依次类推。
------------------------------------------------------------------------------------
--测试数据
create table test(aa varchar(10),bb numeric(10,2))
insert test select '001',50.5
union all select '002',60
union all select '003',15.4
union all select '004',25
union all select '005',48
union all select '006',37
go
--查询函数
create function fn_search(@Num numeric(10,2))
returns @r table (aa varchar(10),bb numeric(10,2))
as
begin
declare @t table (aa varchar(8000),aa1 varchar(10),bb numeric(10,2),level int)
declare @l int
insert @r select aa,bb from test where bb=@num
if @@rowcount>0 goto lb_exit
set @l=0
insert @t select ','+aa+',',aa,bb,@l from test where bb<@num
while @@rowcount>0
begin
insert @r select distinct a.aa,a.bb
from test a,(
select a.aa,a.bb,aa1=b.aa from test a,@t b
where b.level=@l
and b.aa1<a.aa
and a.bb=@num-b.bb
)b where a.aa=b.aa or charindex(','+a.aa+',',b.aa1)>0
if @@rowcount>0 goto lb_exit
set @l=@l+1
insert @t select b.aa+a.aa+',',a.aa,a.bb+b.bb,@l
from test a,@t b
where b.level=@l-1
and b.aa1<a.aa
and a.bb<@num-b.bb
end
lb_exit:
return
end
go
--调用测试1
select * from dbo.fn_search(25)
/*--结果
aa bb
---------- ------------
004 25.00
(所影响的行数为 1 行)
--*/
--调用测试2
select * from dbo.fn_search(135.5)
/*--结果
aa bb
---------- ------------
001 50.50
002 60.00
004 25.00
005 48.00
006 37.00
(所影响的行数为 5 行)
--*/
--调用测试3(找不到的,无返回值)
select * from dbo.fn_search(135.7)
/*--结果
aa bb
---------- ------------
(所影响的行数为 0 行)
--*/
go
drop table test
drop function fn_search
分享到:
相关推荐
在实现合计金额功能时,我们需要遍历Ztree中的所有节点,获取“金额”字段的值,然后进行累加计算。 **GridView(ASP.NET)** GridView是ASP.NET中的一个控件,用于显示数据源(如数据库)中的数据,并允许用户进行...
求出Excel各项目极值的合计数.rar,在日常工作中,用户可能会遇到求极值的问题,本例技巧将向读者介绍数据库函数在三维引用中的使用。本例所示,在两列数据中,求出各项目最大金额的总和。为了便于读者理解,还将其中...
// 如果当前行是合计行,则计算合计值并移除该行 if (dgInput.Rows[iRow].Cells["QTY"].Value != null) { dSumQty += decimal.Parse(dgInput.Rows[iRow].Cells["QTY"].Value.ToString()); } if (dgInput.Rows...
最后,获取到显示总金额的页面元素,并更新其内容为“总金额:”加上计算出的总金额值。 3. `iniEvent()` 函数:此函数用于初始化事件,即在页面加载时为每个“item”名称的复选框绑定`calculateMoney()`函数。这样...
1. **自动生成合计**: 在Excel中,我们可以通过SUM函数来快速计算某一列或行的总和。例如,如果你有一列记录了员工的每日工资,可以使用SUM函数在最后一行自动计算出所有工资的总和。公式可能如下所示: ``` =...
通过VBA,你可以编写一段代码,将所有分项总价加总,得出总金额。VBA的优势在于,它能实现复杂逻辑和重复操作的自动化,大大提高了工作效率。 综上所述,这个压缩包文件提供了一次全面的学习机会,涵盖了数据分析、...
本资源主要介绍NC65单据开发进阶的相关知识点,包括环境信息获取、默认值设置、表头表尾编辑前后事件、金额合计、表体编辑前后事件、默认勾选、业务规则等。 环境信息获取: 环境信息获取是指在NC65开发中获取当前...
文档"NC-SCM-COMMON-V63数量单价金额原本币公共算法.docx"主要阐述了在供应链管理中涉及的复杂数量、单价和金额计算的逻辑,特别关注了国内外业务中货币转换的问题。该算法涉及到Java编程语言,用于处理各种交易场景...
在本文中,我们将深入探讨一个具体的技术问题:如何在用户更改购物车中产品的数量后,通过点击“更新数据量”按钮,实现在Datagrid中动态计算并显示每个产品的子总计和所有产品的总合计。 ### 一、理解问题背景 ...
首先,我们要解决的问题是如何在分页的表格中显示所有金额的总数。`footerFormatter` 是 Bootstrap Table 提供的一个功能,用于自定义页脚单元格的内容。在您的场景中,您尝试使用 `footerFormatter` 来计算并显示总...
9. **月月合计**:可能包含在产销量值表中,用于追踪每月的生产销售情况,便于及时发现问题并调整策略。 使用这样的表格,企业能够实时监控库存水平,预测需求,评估销售表现,同时也可以帮助管理层识别销售趋势,...
内容索引:C#源码,菜单窗体,单选框,复选框 C#获取单选框、复选框的值并对获取的值进行叠加计算,程序原型是一个电脑装机报价单,当你每选一样东西的时候,右侧就会适时显示,并对左边选择的物品的值进行累加计算出...
在MySQL数据库操作中,有时我们需要将一个表中的字段值更新为另一个表中相应字段的值。这在数据同步、数据修复或数据整合等场景中非常常见。本篇将详细讲解如何实现这一操作,并通过实例来具体说明。 首先,我们要...
当用户在输入框中输入数据时,JavaScript可以通过监听`oninput`或`onChange`事件来实时更新合计值。例如,可以通过遍历所有相关`<td>`元素,提取其值,转换为数字,然后累加得到总和。 此外,"效果图.png"很可能是...
一.得到选中的表体行数,列数等内容(总行数和当前选中的行数) 2 二.设置初始化界面时的默认值 3 三....四.在报表中显示合计行 4 ... 改变焦点自动显示表头金额的值 13 二十六.设置行选中的状态 13
在这个例子中,如果“借方金额合计”与“贷方金额合计”相等,就显示实际的合计值,否则显示“借贷不平”。 IF函数的应用远不止这些,它还可以与其他函数如COUNTIF、VLOOKUP等结合,实现更为复杂的数据筛选、分类和...
Vue 2.0 计算list循环后累加值的实例 computed 属性 在 Vue 2.0 中,computed 属性是一个计算属性,它可以根据依赖项自动更新。computed 属性的值是一个函数,该函数的返回值将作为计算属性的值。在上面的代码中,...
7. **程序调试**:通过使用`printf`进行中间值的打印,或者使用调试器,帮助找出程序中的潜在错误。 8. **代码风格和规范**:良好的代码应该遵循一定的编码规范,如变量命名清晰,代码结构清晰,注释充足,以便于...
3. **公式计算**:利用Excel的内置函数,如SUM、AVERAGE等,可以快速计算应收账款的总额、平均值、最大值和最小值,为管理层提供决策依据。 4. **条件格式**:通过设置条件格式,可以突出显示超期未付的应收账款,...