mssql 默认参数怎样处理? - MS-SQL Server / 基础类
我定义一个函数,有五个参数
但实际上我调用时不一定传五个参数,有时只需要传二个参数,有时只需要传三个参数等等
这种参数怎么定义呢?
SQL code:
CREATE FUNCTION [ owner_name.] function_name
( [ { @parameter_name [AS] scalar_parameter_data_type [ = default ] } [ ,...n ] ] )
RETURNS scalar_return_data_type
[ WITH < function_option> [ [,] ...n] ]
[ AS ]
BEGIN
function_body
RETURN scalar_expression
END
SQL code:
设默认值
default
参数的默认值。如果定义了 default 值,则无需指定此参数的值即可执行过程。默认值必须是常量或 NULL。如果过程使用带 LIKE 关键字的参数,则可包含下列通配符:%、_、[] 和 [^]。
USE AdventureWorks;
GO
IF OBJECT_ID ( 'HumanResources.usp_GetEmployees2', 'P' ) IS NOT NULL
DROP PROCEDURE HumanResources.usp_GetEmployees2;
GO
CREATE PROCEDURE HumanResources.usp_GetEmployees2
@lastname varchar(40) = 'D%',
@firstname varchar(20) = '%'
AS
SELECT LastName, FirstName, JobTitle, Department
from HumanResources.vEmployeeDepartment
WHERE FirstName LIKE @firstname
AND LastName LIKE @lastname;
GO
SQL77兄:
能不能举个例子?
2楼不就是例子吗
bancxc兄:
不是存储过程,是自定义函数
存储过程是可以的
{{-
相关问答:
执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......
protected void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Server = (local);user id = sa;pwd = 1;database = Login");
&nb ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
第一句:
select ht.gfdm,gfdm.gfmc,gfdm.lb ,sum(jh.htdj*jh.htsl)as je
from ht left join gfdm on ht.gfdm=gfdm.gfdm
join jh on ht.htbh=jh.hth
and ht.htbh not like'del%' and ht. ......
update test set qty = qty - 1 where (location,sku,valid_date)
in (select location,sku,min(valid_date) from test
where location = 'chuwei' and item_code = '5678' group by location,sku)
以上语 ......