您的位置:首页 > 数据库

sql 自定义函数 ,where后拼接条件跳转语句,实现可变参数查询

2012-07-13 11:05 1251 查看
and ( @kscode is null or ( tbzdqk.kscode = @kscode and @kscode is not null ) ) 在where 条件语句之后加上如此 语句即可实现。

其中 @kscode就是那个可变参数,这里我将@kscode这个参数默认设为 null。

函数定义(关键看@kscode的定义)如下:

ALTER FUNCTION [dbo].[FeatureStat]
(
-- Add the parameters for the function here
@Annual smallint , @kscode nvarchar(15) = null
)
RETURNS @StatTB TABLE( coverArea float , destroyArea float , recoveryArea float , solidStock float , waterLossArea float ,disasterNum int )
AS
begin

..........

...................
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: