August 17, 2009 at 9:53 am
alter fnEmp
(@empid)
begin
select * from tblemp
or
select * from tblemp where empid=@empid
in the above function how can i handle parameter when there is no value or null value.
I dont want the function to fail when a paramter is passed or not, in both scenarios it should exec either of the query.
August 17, 2009 at 10:02 am
select * from tblemp where empid=isnull(@empid,empid)
You can change your select to something like above. Does that work?
August 17, 2009 at 10:06 am
in that case i think i have to change parameter to
alter fnEmp
(
@empid vatchar(5)=null
)
right?
August 17, 2009 at 10:21 am
I don't think default values work for functions, though I could be wrong. Either way though, what Matt wrote will work, you don't really need to change your function declaration at all.
August 17, 2009 at 11:44 am
I believe that is correct... you actually have to use the word "DEFAULT" for unknown parameters in a function.
You should also be aware that functions cannot return result sets directly. They can only return result sets as a Table Valued Function and then you must use the function in the FROM clause of the calling proc or script.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply