create function Xtest
(@d1 varchar(3)=null
,@d2 varchar(3)=null)
returns table
as
return
with code_list(code_pattern)
as
(
select x.code_pattern
from (values (@d1),(@d2)) as x(code_pattern)
where x.code_pattern is not null
),y
as
(
select substring(code,1,3) as code
from tblicd
where substring(code,1,3) in
(
select * from code_list
)
)
select * from y
は完全に終了したら意味をなさない私の関数です。このクエリを実行しようとすると、2つのパラメータを指定しないと、失敗します。私はストアドプロシージャと同じコードを持っていて、1つのパラメータだけを入力すると、うまく動作し、2番目のパラメータnullが割り当てられます。パラメータが提供されていない場合、例えば、ストアドプロシージャのようにnull
をパラメータ値として渡すことができる方法はありますか?テーブル値関数にパラメータのデフォルト値を渡す
関数がコンパイルされます。
関連する、おそらく少なくとも1つはおそらくゥープです:http://stackoverflow.com/questions/3278860/optional-parameter-in-sql-server ... http://stackoverflow.com/questions/12721869/alter -a-sql-server-function-to-accept-new-optional-parameter ... http://stackoverflow.com/questions/8358315/t-sql-function-with-default-parameters –