日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
SQL函數(shù)和存儲過程模板示例

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

--標量值函數(shù)

-- ================================================
-- 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:  
-- Create date:
-- Description:
-- =============================================
CREATE FUNCTION
(
-- Add the parameters for the function here
<@Param1, sysname, @p1>
)
RETURNS
AS
BEGIN#p#
-- Declare the return variable here
DECLARE <@ResultVar, sysname, @Result>

-- 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

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

--內(nèi)聯(lián)表值函數(shù)

-- ================================================
-- 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:  
-- Create date:
-- Description:
-- =============================================
CREATE FUNCTION
(
-- Add the parameters for the function here
<@param1, sysname, @p1> ,
<@param2, sysname, @p2>
)
RETURNS TABLE #p#
AS
RETURN
(
-- Add the SELECT statement with parameter references here
SELECT 0
)
GO

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

--多語句表值函數(shù)

-- ================================================
-- 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:  
-- Create date:
-- Description:
-- =============================================
CREATE FUNCTION
(
-- Add the parameters for the function here
<@param1, sysname, @p1> ,
<@param2, sysname, @p2>
)
RETURNS #p#
<@Table_Variable_Name, sysname, @Table_Var> TABLE
(
-- Add the column definitions for the TABLE variable here
,

)
AS
BEGIN
-- Fill the table variable with the rows for your result set

RETURN
END
GO

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

--多語句表值函數(shù)

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函數(shù)和存儲過程模板示例
標題網(wǎng)址:http://www.dlmjj.cn/article/dheicde.html