成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

SQL函數和存儲過程模板示例

數據庫 SQL Server
函數和存儲過程在SQL中都是很重要的,下文將為您介紹SQL函數和存儲過程模板,供您參考,希望對您有所幫助。

學習SQL數據庫,函數和存儲過程都是非常重要的,下面就將為您示例SQL函數和存儲過程模板,供您參考,希望對您學習SQL函數和存儲過程能有所啟迪。

--標量值函數
 

-- ================================================
-- Template generated from Template Explorer using:
-- Create Scalar Function (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the function.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:   <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <Description, ,>
-- =============================================
CREATE FUNCTION <Scalar_Function_Name, sysname, FunctionName>
(
-- Add the parameters for the function here
<@Param1, sysname, @p1> <Data_Type_For_Param1, , int>
)
RETURNS <Function_Data_Type, ,int>
AS
BEGIN#p#
-- Declare the return variable here
DECLARE <@ResultVar, sysname, @Result> <Function_Data_Type, ,int>

-- Add the T-SQL statements to compute the return value here
SELECT <@ResultVar, sysname, @Result> = <@Param1, sysname, @p1>

-- Return the result of the function
RETURN <@ResultVar, sysname, @Result>

END
GO

--////////////////////////////////////////////////////////////////////////////////////////////////////////////

--內聯表值函數

-- ================================================
-- Template generated from Template Explorer using:
-- Create Inline Function (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the function.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:   <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE FUNCTION <Inline_Function_Name, sysname, FunctionName>
(
-- Add the parameters for the function here
<@param1, sysname, @p1> <Data_Type_For_Param1, , int>,
<@param2, sysname, @p2> <Data_Type_For_Param2, , char>
)
RETURNS TABLE #p#
AS
RETURN
(
-- Add the SELECT statement with parameter references here
SELECT 0
)
GO


--//////////////////////////////////////////////////////////////////////////////////////////////////////////////

--多語句表值函數

-- ================================================
-- Template generated from Template Explorer using:
-- Create Multi-Statement Function (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the function.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:   <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE FUNCTION <Table_Function_Name, sysname, FunctionName>
(
-- Add the parameters for the function here
<@param1, sysname, @p1> <data_type_for_param1, , int>,
<@param2, sysname, @p2> <data_type_for_param2, , char>
)
RETURNS #p#
<@Table_Variable_Name, sysname, @Table_Var> TABLE
(
-- Add the column definitions for the TABLE variable here
<Column_1, sysname, c1> <Data_Type_For_Column1, , int>,
<Column_2, sysname, c2> <Data_Type_For_Column2, , int>
)
AS
BEGIN
-- Fill the table variable with the rows for your result set

RETURN
END
GO

--//////////////////////////////////////////////////////////////////////////////////////////////////////////////

--多語句表值函數

DECLARE @MergeDate Datetime
DECLARE @MasterId Int
DECLARE @DuplicateId Int

SELECT @MergeDate = GetDate()


DECLARE merge_cursor CURSOR FAST_FORWARD FOR SELECT MasterCustomerId, DuplicateCustomerId FROM DuplicateCustomers WHERE IsMerged = 0

OPEN merge_cursor

FETCH NEXT FROM merge_cursor INTO @MasterId, @DuplicateId

WHILE @@FETCH_STATUS = 0
BEGIN
EXEC MergeDuplicateCustomers @MasterId, @DuplicateId

UPDATE DuplicateCustomers
SET
IsMerged = 1,
MergeDate = @MergeDate
WHERE
MasterCustomerId = @MasterId AND
DuplicateCustomerId = @DuplicateId

FETCH NEXT FROM merge_cursor INTO @MasterId, @DuplicateId
END

CLOSE merge_cursor
DEALLOCATE merge_cursor

 

 

【編輯推薦】

SQL中表變量是否必須替代臨時表

SQL中表變量的不足

詳解SQL中循環結構的使用

SQL循環執行while控制

SQL循環語句的妙用

 

 

責任編輯:段燃 來源: 互聯網
相關推薦

2009-08-06 16:18:38

C#調用SQL存儲過程

2011-09-01 15:40:42

SQL Server存儲過程和存儲函數的加

2011-08-22 10:15:39

數據庫存儲過程

2023-02-28 11:29:09

存儲函數MySQL

2010-10-09 17:08:15

MySQL存儲過程

2010-09-25 16:00:38

sql存儲過程

2011-08-16 16:59:58

PLSQL分頁存儲過程Java

2010-09-14 17:20:39

SQL函數

2010-10-12 10:48:02

mysql存儲過程

2018-03-16 08:41:16

Oracle存儲函數

2011-03-31 10:38:28

SQL Server編寫優化

2011-07-11 13:22:28

存儲過程

2011-09-01 17:25:03

SQL Server 查看死鎖存儲過程

2011-08-12 14:01:21

SQL Server存儲過程

2010-07-15 12:38:14

SQL Server存

2009-08-06 16:44:06

2010-10-29 16:22:37

SQL存儲過程

2010-09-07 11:41:24

SQL語句

2010-09-06 15:41:34

SQL函數存儲過程

2010-09-06 16:52:17

SQL函數
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 激情婷婷 | 成人自拍视频网站 | 精品一区二区三区入口 | 成年人网站免费视频 | 在线一级片| 精精国产xxxx视频在线播放7 | 成人激情视频在线播放 | 自拍视频精品 | 欧美寡妇偷汉性猛交 | 一级黄色日本片 | 91影院| 国产精品精品视频一区二区三区 | 国产伦精品一区二区三区高清 | 亚洲免费精品一区 | 国产在线一区二区 | 日韩精品成人在线 | 在线观看av网站永久 | 性一交一乱一透一a级 | 中文字幕一区二区三区在线观看 | 久久国产成人精品国产成人亚洲 | 韩国精品一区二区三区 | 国产精品久久久久久久岛一牛影视 | 一区二区国产在线观看 | 国产中文一区二区三区 | 亚洲免费在线观看av | 天天综合网91 | 国产乱码精品1区2区3区 | 国产视频一二三区 | 在线观看国产精品一区二区 | 午夜影院在线观看 | 欧美视频三区 | 国产日韩精品在线 | 97操操| 人妖无码 | 日韩在线观看一区 | 日韩成人免费视频 | 国产 欧美 日韩 一区 | 亚洲欧美一区二区三区情侣bbw | 欧美中文字幕在线观看 | 国产精品一区二区在线 | 亚洲视频在线播放 |