CREATE FUNCTION fn_roles(@userid varchar(36))
RETURNS TABLE
AS
RETURN
SELECT *
FROM user_roles
WHERE userid = @userid
My function accepts a parameter @userid
and returns roles that the user is assigned to from the user_roles
table.
What if I want to return all records from the user_roles
table if a NULL
value for the parameter is passed? What would be the most elegant way to handle that?