Query in Reports [message #438532] |
Sun, 10 January 2010 11:48 |
sreejith.s
Messages: 26 Registered: November 2009
|
Junior Member |
|
|
Hi All,
I have a group above report which works perfectly fine and looks like this:
empnum empname leavetype ..................
100 abc 1
101 def 6
102 hij 12
Now, I have another table where:
Leave.code Leave.name
1 annual leave
..
6 sick leave
etc etc....
I need my report to display the leave.name under leavetype rather than displaying the code. I cannot take the leave.name directly from the table, so need to write a function where based on each leave.code, the corresponding leave.name is displayed.
Any help with the query for this or pointers would be highly appreciated.
Regards,
Sreejith
|
|
|
Re: Query in Reports [message #438533 is a reply to message #438532] |
Sun, 10 January 2010 12:17 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
Quote:I cannot take the leave.name directly from the table Why not? It is the most straightforward way to do that; something like
select e.empnum, e.empname, l.name leave_name
from employees e,
leave l
where l.code = e.leave_type
If you insist on a function, you can do that using several options. One of them is to create a formula column which would look like retval leave.name%type;
begin
select l.name
into retval
from leave l
where l.code = :leave_type; -- :leave_type is a column fetched
-- in the main report query
return (retval);
end;
Another option is to create a database function and call it from the report:create or replace function fun_leave_type (par_leave_type in number)
return char
is
retval leave.name%type;
begin
select l.name
into retval
from leave l
where l.code = par_leave_type; -- par_leave_type is argument passed from the report
return (retval);
end;
In the report's query:
select e.empnum, e.empname, fun_leave_type(e.leave_type) leave_name
from employees e
There might be other options, but I guess that those three are the most obvious. However, the first one is the most trivial. Why can't you use it, again?
|
|
|
|
Re: Query in Reports [message #438677 is a reply to message #438534] |
Mon, 11 January 2010 13:43 |
sreejith.s
Messages: 26 Registered: November 2009
|
Junior Member |
|
|
Hi Littlefoot,
I did try out the second method today. But there seems to be some confusion i guess. Maybe the table's I mentioned dint really give out the right information.
The reason I cant use the leave.name directly is because there is no way to link it to any of the other three tables that i've used in the query for my report whereas the leave.id column is part of one of those tables and hence it is returned in the report.
So here we go again...the report actually looks like this:
empnum empname absencetype
1 abc 21
2 def 12
3 hij 6
and the table that cant be linked to the ones i use in my query looks like this: (absence_types_f)
absencetype absencename
21 annual leave
12 sick leave
6 death leave
etc...
Again, in the main report I need the absencename to be displayed under absencetype. Also, I'm using the format trigger from the property inspector to do this. Hope that's the right way to go about it.
Regards,
Sreejith
|
|
|
|
Re: Query in Reports [message #438791 is a reply to message #438682] |
Tue, 12 January 2010 04:59 |
sreejith.s
Messages: 26 Registered: November 2009
|
Junior Member |
|
|
Hi Littlefoot,
Apologise for the lack of clarity.
The reason absence_type is being displayed in the report is because it is part of two different tables. The absence_type that is displayed in the report is not queried from the table that I have mentioned above.
Just to make myself more clear, I have a table hrp_people which has absence_type as one of the columns and from where the report queries the data.
I have another table absence_types_f which again has absence_type and absence_name as columns and the data as shown above.
Aprreciate your response.
Regards
Sreejith
|
|
|
|
|
|
|