标题: 一個生成指定空的行的函數。 [打印本页] 作者: HG 时间: 2002-9-29 17:14 标题: 一個生成指定空的行的函數。 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語句部分出了問題,
但我還沒找到原因,請各位幫忙,指點一下?多謝!作者: HG 时间: 2002-9-29 17:24
TMD,原因很簡單.while語句,只有在值為真時,才執行語句塊。
而我的while(@var <0)就否認了,整個語句的執行,所以現在把“<”改為“>”即可。作者: HG 时间: 2002-9-29 17:39
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會壓縮空白行。作者: HG 时间: 2002-9-29 18:25 标题: 我想自荐当版主,不知如何? /*
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行。作者: zhuyiwen 时间: 2002-9-29 21:34
T-SQL的自定义函数,我几乎没用过,看来也不错。谢谢启迪。