• tomyang03 - Monday, December 18, 2017 1:46 PM

    An integer salary? A company where the personnel have hundred character names written in Unicode Chinese? Why don’t you know that the expression “@generic_id = NULL†will always test to a constant value of unknown? The department identifier cannot be an integer or any other numeric; you’re not do any math on it (do you often take the square root of your credit card numbers?)

    There is no such crap as @id in RDBMS. An identifier must identifysomething in particular, not some just vague generic entity.
    SQL is a declarative language,, So we don’t like to use local variableslike are doing.

    Using functions, because you don’t know how to write the SQL, prevents the optimizer from being able to do anything. That used to work in the old procedural languages.

    Finally,you seem to believe that a manager is a totally different creature from an employee. In a properly designed schema, being a manager would be the value of a job title attribute. You’re still building assembly language pointer chains, and not writing RDBMS at all!

    I would suggest you look up the nested set model of hierarchies and use that to build your personnel tables.

    Please post DDL and follow ANSI/ISO standards when asking for help.