SQL SERVER存储过程,参数默认值设置
2014-07-12 23:51
239 查看
Example1:
USE AdventureWorks2008R2;
GO
IF OBJECT_ID('Sales.uspGetSalesYTD', 'P') IS NOT NULL
DROP PROCEDURE Sales.uspGetSalesYTD;
GO
CREATE PROCEDURE Sales.uspGetSalesYTD
@SalesPerson nvarchar(50) = NULL -- NULL default value
AS
SET NOCOUNT ON;
-- Validate the @SalesPerson parameter.
IF @SalesPerson IS NULL
BEGIN
PRINT 'ERROR: You must specify the last name of the sales person.'
RETURN
END
-- Get the sales for the specified sales person and
-- assign it to the output parameter.
SELECT SalesYTD
FROM Sales.SalesPerson AS sp
JOIN HumanResources.vEmployee AS e ON e.BusinessEntityID = sp.BusinessEntityID
WHERE LastName = @SalesPerson;
RETURN
GO
Example 2:
IF OBJECT_ID('dbo.my_proc', 'P') IS NOT NULL
DROP PROCEDURE dbo.my_proc;
GO
CREATE PROCEDURE dbo.my_proc
@first int = NULL, -- NULL default value
@second int = 2, -- Default value of 2
@third int = 3 -- Default value of 3
AS
SET NOCOUNT ON;
SELECT @first, @second, @third;
GO
USE AdventureWorks2008R2;
GO
IF OBJECT_ID('Sales.uspGetSalesYTD', 'P') IS NOT NULL
DROP PROCEDURE Sales.uspGetSalesYTD;
GO
CREATE PROCEDURE Sales.uspGetSalesYTD
@SalesPerson nvarchar(50) = NULL -- NULL default value
AS
SET NOCOUNT ON;
-- Validate the @SalesPerson parameter.
IF @SalesPerson IS NULL
BEGIN
PRINT 'ERROR: You must specify the last name of the sales person.'
RETURN
END
-- Get the sales for the specified sales person and
-- assign it to the output parameter.
SELECT SalesYTD
FROM Sales.SalesPerson AS sp
JOIN HumanResources.vEmployee AS e ON e.BusinessEntityID = sp.BusinessEntityID
WHERE LastName = @SalesPerson;
RETURN
GO
Example 2:
IF OBJECT_ID('dbo.my_proc', 'P') IS NOT NULL
DROP PROCEDURE dbo.my_proc;
GO
CREATE PROCEDURE dbo.my_proc
@first int = NULL, -- NULL default value
@second int = 2, -- Default value of 2
@third int = 3 -- Default value of 3
AS
SET NOCOUNT ON;
SELECT @first, @second, @third;
GO
相关文章推荐
- SQL SERVER存储过程,参数默认值设置
- 在Function中设置参数的默认值的小技巧
- 一行命令获取当前JVM所有可设置的参数以及当前默认值
- Vs2013 类派生+默认值+参数数组,默认值设置不当导致IDE奔溃或编译错误:-1073740791
- Swift语言中为外部参数设置默认值可变参数常量参数变量参数输入输出参数
- 给js function的参数设置默认值
- SQL SERVER2000 存储过程 设置传入参数默认值
- 举例说明如何为JavaScript的方法参数设置默认值
- js函数参数设置默认值
- js设置function参数默认值(适合没有传参情况)
- TestComplete如何设置参数默认值
- shell读取参数,并设置默认值
- js函数参数设置默认值
- java中函数的参数不能设置默认值
- js函数参数设置默认值的一种变通实现方法
- C#基础加强--this 的用法(重载构造方法,设置构造方法中参数的默认值)
- 如何给报表参数设置动态默认值
- js函数参数设置默认值
- 函数参数设置默认值
- 举例说明如何为JavaScript的方法参数设置默认值