设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1845|回复: 4
打印 上一主题 下一主题

一個生成指定空的行的函數。

[复制链接]
跳转到指定楼层
1#
发表于 2002-9-29 17:14:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
alter function ufn_filler_tex_space (@my_space_row as tinyint)  
returns @tbl_filler_tex_space table (wage_date_year  smallint,wage_date_month  tinyint,emp_name  nvarchar(4),emp_idcrad  varchar(18),wage_earning  smallmoney,wage_out_tex  smallmoney)  
as   
begin
     while  (@my_space_row < 0)  
         begin
             insert into @tbl_filler_tex_space values(@my_space_row,null,null,null,null,null)  
             set @my_space_row = @my_space_row -1
         end
      return  
   end  
-------------------------------
調用方法:select * from ufn_filler_tex_space(12)即可產生12個空白行
但現在的問題是,沒有達到預期效果。其中應是while語句部分出了問題,
但我還沒找到原因,請各位幫忙,指點一下?多謝!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
 楼主| 发表于 2002-9-29 17:24:00 | 只看该作者
TMD,原因很簡單.while語句,只有在值為真時,才執行語句塊。
而我的while(@var <0)就否認了,整個語句的執行,所以現在把“<”改為“>”即可。
3#
 楼主| 发表于 2002-9-29 17:39:00 | 只看该作者
alter procedure usp_qry_peson_tex(@my_year as smallint,@my_month as tinyint)
  as   
   --declare @my_row as tinyint
    --select @my_row =(select count(*)/39 from uv_qry_peson_tex)
    select * from uv_qry_peson_tex where wage_date_year = @my_year and wage_date_month = @my_month  
    union  
    select * from uv_qry_peson_tex_history where wage_date_year = @my_year and wage_date_month = @my_month  
   -- union
  -- select * from ufn_filler_tex_space(@my_row)
但奇怪的問題是union會壓縮空白行。
4#
 楼主| 发表于 2002-9-29 18:25:00 | 只看该作者

我想自荐当版主,不知如何?

/*
create function ufn_usp_qry_peson_tex_ok(@my_year as smallint,@my_month as tinyint)
returns @tbl_qry_peson_tex_ok table (wage_date_year smallint,wage_date_month tinyint,emp_name nvarchar(4),emp_idcrad varchar(18),wage_earning smallmoney,wage_out_tex smallmoney)
as
begin
  declare @my_row as tinyint
  select @my_row =(select count(*)/39 from uv_qry_peson_tex)
  insert into @tbl_qry_peson_tex_ok select * from uv_qry_peson_tex where wage_date_year=@my_year and wage_date_month=@my_month union select * from uv_qry_peson_tex_history where wage_date_year = @my_year and wage_date_month = @my_month
  insert into @tbl_qry_peson_tex_ok select * from ufn_filler_tex_space(@my_row)
return
end
*/
select * from ufn_usp_qry_peson_tex_ok(2002,8)
這就是報表尾補空白的SQL原代碼。報表為每頁39行。

点击这里给我发消息

5#
发表于 2002-9-29 21:34:00 | 只看该作者
T-SQL的自定义函数,我几乎没用过,看来也不错。谢谢启迪。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-6-4 17:49 , Processed in 0.180059 second(s), 28 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表