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
은 완전히 완료되면 의미가있는 함수입니다. 이 쿼리를 실행하려고하는데 두 개의 매개 변수를 제공하지 않으면 실패합니다. 저장 프로 시저와 동일한 코드가 있는데 하나의 매개 변수 만 입력하면 잘 작동하고 두 번째 매개 변수 null이 할당됩니다. 매개 변수 값이 저장 프로 시저로 할 수있는 것처럼 제공되지 않으면 null
을 매개 변수 값으로 전달할 수있는 방법이 있습니까?매개 변수의 기본값을 테이블 반환 함수에 전달
함수가 컴파일되지 않습니다.
관련하여 적어도 하나는 아마도 속임수입니다. 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 –