sqlserver2008創建函數
㈠ sql server 2008 強制 刷新 自定義函數問題
您好,提問者:
如果這個function中定於了表的欄位或者查詢多列,建議從這里優化。
另外,您可以給function中的欄位加個索引,以便快速查詢返回。
㈡ 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<[email protected]
begin
set @result = @result + dbo.RmGetPY(substring(@chn,@j,1))
set @[email protected]+1
end
return @result
end
看看這兩個,典型的取漢字拼音碼的函數
㈢ sql server 中如何查看自定義函數的源代碼
可按如下方法查詢,以sqlserver2008為例:
1、登錄SQL
Server
Management
Studio。
2、展開左邊的樹,先在資料庫中找到自己創建自定義函數的庫,如資料庫-系統資料庫-master。
3、依次點擊可編程性-函數-標量值函數,如曾經創建過一個叫「fn_myget」的自定義函數,就能看見。
4、右鍵此函數,點擊編輯,就能看到這個函數的源代碼。
5、代碼如圖,紅框部分即為源代碼。
㈣ SqlServer2008如何用函數獲取錶行數
兩種方法:
--1
selectcount(1)fromtable_temp;
COUNT(*)
---------
12710
實際IO:31
--2
selectMAX(ROWNUM)fromtable_temp
MAX(ROWNUM)
-----------
12710
實際IO:47
第一種方法速度更快