0

I'm working on an assignment and am having trouble with this question:

*Display the department name and the name of all employees plus their manager status. Status should show message ‘is a Manager’ for those who are managers. For those who are not managers show the message ‘is NOT a Manager’. Include also empty departments as well, where the status value should be ‘NO Manager yet’
Display those people who are managers first followed by those whoa are NOT managers and empty departments last. Within those groupings sort by the employee name alphabetically. Here is the heading sample.

Department Name Employee Manager Status*

I know NVL can be used to account for null values, but this question's stumped me.

The tables relevant to this question are:

emp:

Name     Null     Type         
-------- -------- ------------ 
EMPNO    NOT NULL NUMBER(4)    
ENAME             VARCHAR2(10) 
JOB               VARCHAR2(9)  
MGR               NUMBER(4)    
HIREDATE          DATE         
SAL               NUMBER(7,2)  
COMM              NUMBER(7,2)  
DEPTNO   NOT NULL NUMBER(2)  

dept:

desc dept

Name   Null     Type         
------ -------- ------------ 
DEPTNO NOT NULL NUMBER(2)    
DNAME           VARCHAR2(14) 
LOC             VARCHAR2(13) 

If anyone could give me even a hint as to which function I could possibly use to display the strings, instead of the values I would be very greatful!

Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

0

Here is your hint: Use a CASE expression to assign values to your "Manager Status" column, something like:

CASE WHEN condition 
        THEN 'is a Manager'
        ELSE 'is NOT a Manager'
   END as Manager_Status

"condition" will be some value that, if "true" identifies a manager.

BellevueBob
  • 9,498
  • 5
  • 29
  • 56
  • 1
    @user2491621 You're welcome. BTW, the best way to thank people who answer your questions is by "upvoting" the answer. Then separately "accept" the best answer from all those you received. Unless you are sure the answer you "accept" is absolutely correct, wait a while before accepting any. And finally, welcome to Stack Overflow! – BellevueBob Jun 17 '13 at 00:45
0

Depending of which database you use there is several ways to view strings instead of NULL results. For your DB try look at NVL, NULLIF, NVL2, COALESCE, CASE-WHEN clauses (Oracle) or IIF function (Firebird/Interbase). I don't know which DB you use but most of these are common for most popular DBs.