創建sql自定義函數
❶ 什麼是sql自定義函數
Create Function myFunc(@param1 int,@param2 varchar(50)) returns int
as
begin
......
RETURN 0
end
類似這樣自己建的函數,就是SQL自定義函數,可以自定義參數和返回值的,能夠在查詢語句中使用的。
像max(),min(),getdate(),newid()這些就是系統函數了。
❷ sqlserver中自定義函數
創建自定義缺緩函數:
use 數祥扮猛據謹橋庫名
go
create function 函數名
(@pno int)
returns int
as
begin
declare @a int
if not exists(select * from person where pno=@pno)
set @a=-1
else
set @a=1
return @a
end
調用函數:
use 資料庫名
go
select dbo.函數名(13250)
❸ SQL建自定義函數
一個簡單的自定義求和函拍瞎數
create Function sumnum(@A INT,@B int)
Returns int
As
Begin
Declare
@S int
Set @S='襲轎空'
Select @S=@A+@B
Return (@S)
End
--測試帆粗
--SELECT DBO.sumnum(1,2)
❹ SQL中創建一個用戶自定義函數
CREATE
FUNCTION
DBO.tFProctsHS
(
@name
VARCHAR(10))
RETURNS
INT
--這個根據價格的類型自己修改
AS
begin
DECLARE
@jiage
INT;
select
@jiage=
jiage
from
商品表
where
name=
@name
RETURN
(@jiage)
end
--ceshi
select
DBO.tFProctsHS
('記事本')
❺ SQL創建用戶自定義函數
樓主我只寫了其中一個..基本方法都如此,希望對您有幫助,代碼如下
ALTER FUNCTION [dbo].[sum]
(
@class varchar(100), --所選課程
@username varchar(20) --學生姓名
)
RETURNS int
AS
BEGIN
DECLARE @reun int
SELECT SUN(@class) FROM YOURTABLE WHERE USERNAME=@username
RETURN @reun
END
❻ Microsoft SQL Server如何創建 自定義函數
Create Function RmGetPY(@chn nchar(1))
returns char(1)
as
begin
declare @n int
declare @c char(1)
set @n = 63
select @n = @n +1,@c = case chn when @chn then char(@n) else @c end from(
select top 27 * from (
select chn =
'吖' union all select
'八' union all select
'嚓' union all select
'咑' union all select
'妸' union all select
'發' union all select
'旮' union all select
'鉿' union all select
'丌' union all select
'丌' union all select
'咔' union all select
'垃' union all select
'嘸' union all select
'拏' union all select
'噢' union all select
'妑' union all select
'七' union all select
'呥' union all select
'仨' union all select
'他' union all select
'屲' union all select
'屲' union all select
'屲' union all select
'夕' union all select
'丫' union all select
'帀' union all select @chn) as a
order by chn COLLATE Chinese_PRC_CI_AS
) as b
return(@c)
end
go
Create Function GetAllPY(@chn nvarchar(100))
returns varchar(30)
as
begin
declare @i int,@j int,@result varchar(100)
set @result=''
set @i=len(@chn)
set @j=1
while @j<=@i
begin
set @result = @result + dbo.RmGetPY(substring(@chn,@j,1))
set @j=@j+1
end
return @result
end
看看這兩個,典型的取漢字拼音碼的函數
❼ sql 創建自定義函數
create function grade_fun
(
@學生 decimail(18,1)
)
returns decimail(18,1)
as
begin
declare @a decimail(18,1)
select @a=sum(grade) from 成績慶猜團表譽橘兆仿 where 學生=@學生
return @a
end
❽ 寫一個Sql自定義函數
declare @flag int,@no varchar(20),@return int
--先為變數賦值
--set @flag=0...
select @return = search1(@flag,@no)
我沒明白,是要寫函數的代碼還是寫調用的代碼?調用方法上面已寫。