解决方案 »
- webbrowser中如何让程序等待页面完成
- 请问用delphi 怎么将TIF 文件合并成PDF
- 小弟用fastreport3.0打印报表时,如何控制每页固定的打印行数(比如12行)?
- 如何在MDI程序中屏蔽Alt+F4按钮?
- 求即时消息传输数据包的格式
- 讨论网络游戏封外挂的手段和实现思路(灌水的不要进).
- 来CSDN一年,最后半年都只在水园逛,几乎不来答题为什么我会这么无聊?谁能救救我
- 我用delphi开发时总有一个怪现象,不知道是不是IDE出了问题
- 再谈datetime字段,有没有更好的方法
- 新年送分_03 (限初级新手)
- 请教如何在编辑器里实现如图效果,或有没有这样的控件
- 请教一个delphi OCX的字符兼容性问题
代码怎么写啊?是在delphi进行的
[ID] [int],
[name] nvarchar(50),
[num] decimal(18,10),
[price] decimal(18,10),
[noid] nvarchar(20),
[amount] decimal(18,10)
) ON [PRIMARY]GOSET NOCOUNT ON
DECLARE @id int, @qty1 int, @qty2 decimal(18,10), @qty3 int, @num decimal(18,10), @qty int
DECLARE @name varchar(50), @price decimal(18,10) , @qty4 decimal(18,10), @qty5 decimal(18,10)
DECLARE @str varchar(8000), @str1 varchar(1000)
set @id = 1
set @qty = 500
set @str = N'
WITH cte(ID, name, num, price, noid, amount, qty1, qty2)
as (
select ID, name, num, price, noid, amount, CONVERT (int,(amount/@qty)) as qty1 , CONVERT (float, (amount%@qty)) as qty2 from t11 where id = @id)'DECLARE acursor CURSOR FOR
select num, CONVERT (int,(amount/@qty)) as qty1 , CONVERT (float, (amount%@qty)) as qty2 from t11 where id = @id
OPEN acursor
FETCH NEXT FROM acursor
INTO @num, @qty1, @qty2
set @qty3 = @qty1
if (@qty1 >0)
BEGIN
set @str1 = 'select ID, name, @qty4, price, noid, amount, @qty from cte ';
set @str = @str + ' ' + RTRIM(@str1);
set @qty1 = @qty1-1
ENDWHILE (@qty1 >0)
BEGIN
set @str1 = 'select ID, name, @qty4, price, noid, amount, @qty from cte ';
set @str = @str + ' union all ' + RTRIM(@str1);
set @qty1 = @qty1-1
ENDCLOSE acursor
DEALLOCATE acursorif (@qty2>0)
begin
set @str1 = 'select ID, name, @qty5, price, noid, amount, @qty2 from cte';
set @str = @str + ' union all ' + RTRIM(@str1)
end;set @qty4 = CONVERT(int, (@num / @qty3))
set @qty5 = CONVERT(decimal(18,10), (@num % @qty3))set @str1 = 'DECLARE @id int, @qty int, @qty2 decimal(18,10), @qty3 decimal(18,10), ';
set @str1 = @str1 + '@qty4 nvarchar(20), @qty5 nvarchar(20)' ;
set @str1 = @str1 + ' set @id = ' + CONVERT(nvarchar(20), @id) ;
set @str1 = @str1 + ' set @qty2 = ' + CONVERT(nvarchar(20), @qty2) ;
set @str1 = @str1 + ' set @qty3 = ' + CONVERT(nvarchar(20), @qty3) ;
set @str1 = @str1 + ' set @qty4 = ' + CONVERT(nvarchar(20), @qty4) ;
set @str1 = @str1 + ' set @qty5 = ' + CONVERT(nvarchar(20), @qty5) ;
set @str1 = @str1 + ' set @qty = '+ CONVERT(nvarchar(20), @qty) ;set @str = @str1 + '; '+ @str ;exec(@str)
代码怎么写啊?是在delphi进行的取得产品1的记录,然后 总金额 div 500 得到x,总金额 mod 500 得到y
那么从第1到第x条记录都是产品1的金额为500的记录
第x+1条记录为产品1的金额为y的记录
总金额; amount := 1600 ;你直接
for i:=0 to Trunc(amount/500) do
begin
插入到 dbgrid 一条记录;
end;if (amount mod 500 > 0)
begin
插入该记录的最后一条到 dbgrid ;
end;
as
(select *, convert(decimal(18,2), amount) as tmp from t1)
,
cte2(id, name, price, qty, did, amount, tmp)
as
(select * from cte1
union all
select a.id, a.name, a.price, a.qty, a.did, a.amount,
convert(decimal(18,2), (a.tmp - 500)) as tmp from cte2 a where a.tmp - 500 > 0
)
select id, name, did, qty, price, amount,
case when tmp > 500 then 500 else tmp end as tmp from cte2
order by id, name ----------------------------------------------------------------------------------------------------
1 产品1 20808001 137.28 13.00 1784.68 500.00
1 产品1 20808001 137.28 13.00 1784.68 500.00
1 产品1 20808001 137.28 13.00 1784.68 500.00
1 产品1 20808001 137.28 13.00 1784.68 284.68
2 产品2 20808001 154.12 10.00 1542.12 500.00
2 产品2 20808001 154.12 10.00 1542.12 500.00
2 产品2 20808001 154.12 10.00 1542.12 42.12
2 产品2 20808001 154.12 10.00 1542.12 500.00
3 产品3 20808001 239.94 11.00 2639.32 500.00
3 产品3 20808001 239.94 11.00 2639.32 500.00
3 产品3 20808001 239.94 11.00 2639.32 500.00
3 产品3 20808001 239.94 11.00 2639.32 500.00
3 产品3 20808001 239.94 11.00 2639.32 500.00
3 产品3 20808001 239.94 11.00 2639.32 139.32
yangb0803
高手,,你的那存储过程学习了,,不过现在我要用delphi去实现这个功能,有的不太明白,,请再次指教
然后在循环中直取出单条数据, 计算也可以 拖个 ClientDataSet, 将计算出来的记录,一条条插入到 ClientDataSet 然后显示到 dbgrid里