SQL2005 自定義函式

2021-05-22 18:25:49 字數 1217 閱讀 7398

單錶

create function get_pxlb085_zw (@pxlb char(10))

returns varchar(20)

asbegin

declare @sreturnvalue varchar(20)

select @sreturnvalue=o_text from sys_select where s_ename='bs_pxlb' and o_value=@pxlb order by o_order

return @sreturnvalue

end帶游標的查詢

create function fx_get_ldps (@idval as numeric) 

returns nvarchar(4000) as 

begin

declare @reval nvarchar(4000)

declare @nameval nvarchar(100)

declare @conval nvarchar(2000)

declare @dateval nvarchar(50)

declare mycur cursor for  select  u.us_name,content,convert(nvarchar(50), publish_date,20) as publish_date from sys_flow_biz_text t,sys_users u where (t.us_id=u.id and  t.belongto = @idval and t.type_tag='ldps' and t.delete_tag='0') order by t.publish_date

open mycur

fetch next from mycur into @nameval,@conval,@dateval

set @reval = @nameval+':'+@conval

while @@fetch_status = 0

begin

fetch next from mycur into @nameval,@conval,@dateval

if  (@@fetch_status = 0)

set @reval =@reval+'

'+@nameval+':'+@conval

endclose mycur

deallocate mycur

return @reval

end

sql2005關於自定義函式的講解

use caowen 關於函式 沒有返回值,沒有引數的函式 create function t ch asbegin print 曹歡 end 這是呼叫 exec t ch 這是有簡單型別返回值 有引數的函式 create function t go a int,b int returns int ...

SQL自定義函式

建立使用者自定義函式 標量函式 create function dbo.bmrs bmh as int returns int asbegin declare bmrs int select bmrs count 工號 from 銷售人員where 部門號 bmh return bmrs endgo...

sql 自定義函式

delimiter create definer function woshow try aid bigint returns bigint 20 language sql not deterministic sql security comment string begin if aid 0 th...