sql join with default parameter -
assume have table called t_employee has name column , company_id column. have stored procedure can list employees or company,
create procedure p_listemployees( @companyid integer = null)
in procedure, rather saying if @companyid null ..... rather have join deal fact may or may not filtering. sure time ago have seen done using coalesc.
any thoughts?
from t_employee e left join company c on coalesce(c.company_id,1) = coalesce(e.company_id,1)
Comments
Post a Comment