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 
is my function which will make sense when it's fully finished.  If I try to run this query and I don't supply two parameters, it will fail.  I have the same code as a stored procedure and if I only enter one parameter, it works fine and assigns the second parameter null.  Is there a way that I can pass null as a parameter value if the parameter isn't supplied, like one can do with stored procedures?
The function does compile.
 
     
    