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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -