Showing posts with label employees. Show all posts
Showing posts with label employees. Show all posts

Wednesday, March 28, 2012

Newbie question about employee counts

Hello,

I built a table with columns to count the employees. The columns are either Active or Term and if they are Active it has a 1, if not, 0. Same goes for Terms – 1 is they termed and 0 if not. It also has the current effective date.

Then I run a loop that builds a fact table with all the employees in each of the months for a year. So the table looks (something) like this:

RowKeyEmpKeyDeptKeyActiveTermDate

110751020061001

2111001020061001

31392 1 020061001

416921020061001

Then the next month:

RowKeyEmpKeyDeptKeyActiveTermDate

510751020061101

611100 1 020061101

713920120061101

816921020061101

This way I can keep track of who is the active employees each month as well as who terminated that month.and do year to date totals on the terminations, which I need for turnover calculations.

The issue is, when I view the data in a Reporting Services report, and I drill-down to a Department and look who is active, I also see the termed employees. My assumption is because they are part of the count – that part being zero. Is there a better way to approach this?

My guess was not having Active and Terms columns. Instead I thought of a single column with a StatusKey. But if I did that I wouldn’t know how to do the calculations of Year-to-Date terminations.

Any suggestion is greatly appreciated. As well as (constructive) criticism on this technique.

Thank you.

-Gumbatman

I don't see how using YTD can return correct results, because you would end up calculating the same employee as many times as many days he terminated. If you have Active and Term as measures, I'd replays 0 with NULL (there is a property of measure or measure group that says preserve null, I don't remember it's name from the top of my head). Again, if I remember correctly Reporting Services applyes Non Empty to the query, therefore in this case you wan't see employees that have NULL as active, if you use both Employess and Active in the query and you are not drilling down the time. As for calculating number of terminated employes I would use something like this:

count(filter(NonEmpty (employee.members, Term * Time.<today>), IsEmpty ((employe.currentmember, Term, Time.<CurrentYear>.firstchild.firstchild.firstchild)))) //calculates the number of employees that are marked as terminated today, but where still working on january first. Of course if you have laxuary to delete employees from the system that are gone more then a year, you can simplify this formula.

|||

Irina,

Thank you for the information.

What is strange (and I have to look at more closely) is that the YTD terms are calculating correctly even though I am probably double-counting them. I think I only added those who terminated in that year and I added them only to the last month of the year. I have to check that.

What I am still not too clear on is if I drill-down to a Product, will I see the terms and actives who are in that Product when all I want to see is the terms? Will the null, in the terms column, help me with that?

What about combining the Actives and Terms into a single dimension, it is sort of no longer a measure I guess?

Thanks for the help

Wednesday, March 21, 2012

Newbie Query Question

I have three tables I'm trying to query.
Table 1 - Employees
Table 2 - Cell Phones
Table 3 - Pagers
What I'm trying to do is query ALL of the employees in Table 1 and show
either their pager number or cell phone number or still list them even if
both those fields are Null.
Can someone help point me in the right direction. Everytime I try to run my
own query I just get the employees that have both a cell and a pager.
Any information would be greatly appreciated.
Thanks, Correyselect * from Employees E
left outer join CellPhones C on
C.EmployeeID = E.EmployeeID
left outer join Pagers P on
E.EmployeeID = P.EmployeeID
Alain Quesnel
alainsansspam@.logiquel.com
www.logiquel.com
"Correy" <cgrist@.comcast.net> wrote in message
news:euChehtqIHA.2256@.TK2MSFTNGP05.phx.gbl...
>I have three tables I'm trying to query.
> Table 1 - Employees
> Table 2 - Cell Phones
> Table 3 - Pagers
> What I'm trying to do is query ALL of the employees in Table 1 and show
> either their pager number or cell phone number or still list them even if
> both those fields are Null.
> Can someone help point me in the right direction. Everytime I try to run
> my own query I just get the employees that have both a cell and a pager.
> Any information would be greatly appreciated.
> Thanks, Correy
>
>

Wednesday, March 7, 2012

Newbie : Need help in Sorting

I have written a query to find out the total worked hours & total dollars
for the employees who have worked in a particular time period .I need to sort them such that the employees with total amount =0 ( for the given period) come first followed by the employees who are to be paid .
At the end , I want to count the number of employees with total Amt = 0
& then the count of no. of employees who are to be paid . Here is the query

SELECT TAB1.EMP_ID ,
TAB1.EMP_NAME ,
TO_CHAR(ROUND((SUM(TAB1.WRKD_MINUTES))/60,2))
WRKD_HOURS,
TO_CHAR(ROUND(SUM(TAB1.WRKD_MINUTES *
TAB1.WRKD_RATE)/60)) TOTAL_AMT
FROM
( SELECT
EMPLOYEE.EMP_ID,
EMPLOYEE.EMP_NAME,
(EMPLOYEE.EMP_FIRSTNAME||' '||EMPLOYEE.EMP_LASTNAME) FULLNAME,
HOUR_TYPE.HTYPE_NAME,
TIME_CODE.TCODE_NAME,
WORK_DETAIL.WRKD_WORK_DATE,
WORK_DETAIL.WRKD_MINUTES,
WORK_DETAIL.WRKD_RATE,
TO_CHAR(ROUND((WORK_DETAIL.WRKD_MINUTES)/60,2),'9999.00') WRKD_HOURS,
TO_CHAR(ROUND((WORK_DETAIL.WRKD_MINUTES * WORK_DETAIL.WRKD_RATE)/60)) TOTAL_AMT,
CALC_GROUP.CALCGRP_NAME,
PAY_GROUP.PAYGRP_NAME
FROM
EMPLOYEE, HOUR_TYPE,TIME_CODE, WORK_DETAIL,
WORK_SUMMARY, CALC_GROUP, JOB,PAY_GROUP
-- WORKBRAIN_TEAM,EMPLOYEE_TEAM
WHERE
CALC_GROUP.CALCGRP_ID = EMPLOYEE.CALCGRP_ID
AND HOUR_TYPE.HTYPE_ID = WORK_DETAIL.HTYPE_ID
AND HOUR_TYPE.HTYPE_ID = TIME_CODE.HTYPE_ID
-- AND hour_type.htype_name = 'UNPAID'
-- AND time_code.tcode_name = 'UAT'
AND WORK_DETAIL.WRKS_ID = WORK_SUMMARY.WRKS_ID
AND WORK_SUMMARY.EMP_ID = EMPLOYEE.EMP_ID
-- AND WORK_DETAIL.WRKD_WORK_DATE < SYSDATE
-- AND WORKBRAIN_TEAM.WBT_ID = EMPLOYEE_TEAM.WBT_ID
-- AND EMPLOYEE_TEAM.EMP_ID = EMPLOYEE.EMP_ID
AND WORK_DETAIL.JOB_ID = JOB.JOB_ID
AND EMPLOYEE.PAYGRP_ID = PAY_GROUP.PAYGRP_ID ) TAB1
GROUP BY EMP_ID,EMP_NAME

I have tried to group by Total Amount but it does not give the necessary order . Also , the database I am using is Oracle 8I enterprise version 8.1.7.7.0 .When I try to avoid TO_CHAR & just use ROUND , My query goes in a loop .You cannot group by the Total Amount, but you can order by it. Add this at the end:

ORDER BY total_amt

I don't understand your other problem with the ROUND.|||I had earlier tried ORDER BY .But it gives an error message ,
ERROR-937 at Line 1 Column 1 Message :ORA-00937:not a single-group group function.

I was trying to avoid TO_CHAR so that I can test the query by giving conditions such as TOTAL_AMT > 45 etc .When I use TO_CHAR , I cannot use this comparisons .|||If I remove TO_CHAR , My query does not fetch any result & when I try to refresh , it says "Data is being retrieved " .But I know , that the query would not return any results & I have to abort it .|||Originally posted by ritz1975
If I remove TO_CHAR , My query does not fetch any result & when I try to refresh , it says "Data is being retrieved " .But I know , that the query would not return any results & I have to abort it .
Post your query - without the TO_CHARs and with the ORDER BY that you tried. This isn't making sense!|||I again gives the same oracle error msg which i posted .|||Originally posted by andrewst
Post your query - without the TO_CHARs and with the ORDER BY that you tried. This isn't making sense!
I also don't understand why you are doing a select from a select - why not just this:

SELECT
EMPLOYEE.EMP_ID,
EMPLOYEE.EMP_NAME,
ROUND((SUM(WORK_DETAIL.WRKD_MINUTES))/60,2) WRKD_HOURS,
ROUND(SUM(WORK_DETAIL.WRKD_MINUTES * WORK_DETAIL.WRKD_RATE)/60) TOTAL_AMT
FROM
EMPLOYEE, HOUR_TYPE,TIME_CODE, WORK_DETAIL,
WORK_SUMMARY, CALC_GROUP, JOB,PAY_GROUP
-- WORKBRAIN_TEAM,EMPLOYEE_TEAM
WHERE
CALC_GROUP.CALCGRP_ID = EMPLOYEE.CALCGRP_ID
AND HOUR_TYPE.HTYPE_ID = WORK_DETAIL.HTYPE_ID
AND HOUR_TYPE.HTYPE_ID = TIME_CODE.HTYPE_ID
-- AND hour_type.htype_name = 'UNPAID'
-- AND time_code.tcode_name = 'UAT'
AND WORK_DETAIL.WRKS_ID = WORK_SUMMARY.WRKS_ID
AND WORK_SUMMARY.EMP_ID = EMPLOYEE.EMP_ID
-- AND WORK_DETAIL.WRKD_WORK_DATE < SYSDATE
-- AND WORKBRAIN_TEAM.WBT_ID = EMPLOYEE_TEAM.WBT_ID
-- AND EMPLOYEE_TEAM.EMP_ID = EMPLOYEE.EMP_ID
AND WORK_DETAIL.JOB_ID = JOB.JOB_ID
AND EMPLOYEE.PAYGRP_ID = PAY_GROUP.PAYGRP_ID
GROUP BY EMP_ID,EMP_NAME
ORDER BY TOTAL_AMT
?|||Originally posted by ritz1975
I again gives the same oracle error msg which i posted .
Try the version I just posted - or show me the code that you are actually running that gives the error message.|||That's because I have to use the other variables like Hourtpe ,Calcgroup,Paygroup etc . in the report view .I am working on the PL/SQL inside a product called WORKBRAIN ERM (Employee Relationship Management) .

Unless I use these variables in the SELECT ,I cannot define report criteria while designing the report .

I am trying your query now .|||I know nothing about WORKBRAIN ERM, but maybe it is part of the problem. I suggest you try running your query in SQL Plus first. Once it works there, THEN cut and paste it into WORKBRAIN ERM. If it then doesn't work, you know where the problem lies...

I understand that you need to join to various tables to restrict your query, but I still don't see why that should mean you need to use an inline view (SELECT FROM (SELECT FROM))|||I tried to run your code .But it now gives an error message ,
ERROR-918 at Line 1 Column 1 Message :ORA-00918:column ambiguously defined .

I changed the table order in the FROM statement to
EMPLOYEE,WORK_DETAIL,HOUR_TYPE,TIME_CODE,
WORK_SUMMARY, CALC_GROUP, JOB,PAY_GROUP

instead of EMPLOYEE,HOUR_TYPE,TIME_CODE,WORK_DETAIL,
WORK_SUMMARY, CALC_GROUP, JOB,PAY_GROUP

but the result is the same .|||See here is the sample code of the view

CREATE OR REPLACE VIEW REPT_VIEW_IP_S_PAID_UNPAID
(
EMP_ID,
EMP_NAME,
FULLNAME,
HYPE_NAME,
TCODE_NAME,
WRKD_WORK_DATE,
WRKD_MINUTES,
WRKD_HOURS,
TOTAL_AMT,
CALCGRP_NAME,
PAYGRP_NAME
)
AS
SELECT
EMPLOYEE.EMP_ID,
EMPLOYEE.EMP_NAME,
(EMPLOYEE.EMP_FIRSTNAME||' '||EMPLOYEE.EMP_LASTNAME) FULLNAME,
HOUR_TYPE.HTYPE_NAME,
TIME_CODE.TCODE_NAME,
WORK_DETAIL.WRKD_WORK_DATE,
WORK_DETAIL.WRKD_MINUTES,
TO_CHAR(ROUND(SUM(WORK_DETAIL.WRKD_MINUTES)/60,2),'9999.00') WRKD_HOURS,
TO_CHAR(ROUND(SUM(WORK_DETAIL.WRKD_MINUTES * WORK_DETAIL.WRKD_RATE)/60)) TOTAL_AMT,
CALC_GROUP.CALCGRP_NAME,
PAY_GROUP.PAYGRP_NAME
FROM
EMPLOYEE, HOUR_TYPE,TIME_CODE, WORK_DETAIL,
WORK_SUMMARY, CALC_GROUP, JOB,PAY_GROUP
-- WORKBRAIN_TEAM,EMPLOYEE_TEAM
WHERE
CALC_GROUP.CALCGRP_ID = EMPLOYEE.CALCGRP_ID
AND HOUR_TYPE.HTYPE_ID = WORK_DETAIL.HTYPE_ID
AND HOUR_TYPE.HTYPE_ID = TIME_CODE.HTYPE_ID
-- AND hour_type.htype_name <> 'UNPAID'
-- AND time_code.tcode_name <> 'UAT'
AND WORK_DETAIL.WRKS_ID = WORK_SUMMARY.WRKS_ID
AND WORK_SUMMARY.EMP_ID = EMPLOYEE.EMP_ID
-- AND WORK_DETAIL.WRKD_WORK_DATE < SYSDATE
-- AND WORKBRAIN_TEAM.WBT_ID = EMPLOYEE_TEAM.WBT_ID
-- AND EMPLOYEE_TEAM.EMP_ID = EMPLOYEE.EMP_ID
AND WORK_DETAIL.JOB_ID = JOB.JOB_ID
AND EMPLOYEE.PAYGRP_ID = PAY_GROUP.PAYGRP_ID

I am using all those SELECT fields 'coz If I do not select all of them in the same order , I cannot define them under Create view statement|||I had forgotten to put the table aliases on the GROUP BY columns. Try this now:

SELECT
EMPLOYEE.EMP_ID,
EMPLOYEE.EMP_NAME,
ROUND((SUM(WORK_DETAIL.WRKD_MINUTES))/60,2) WRKD_HOURS,
ROUND(SUM(WORK_DETAIL.WRKD_MINUTES * WORK_DETAIL.WRKD_RATE)/60) TOTAL_AMT
FROM
EMPLOYEE, HOUR_TYPE,TIME_CODE, WORK_DETAIL,
WORK_SUMMARY, CALC_GROUP, JOB,PAY_GROUP
-- WORKBRAIN_TEAM,EMPLOYEE_TEAM
WHERE
CALC_GROUP.CALCGRP_ID = EMPLOYEE.CALCGRP_ID
AND HOUR_TYPE.HTYPE_ID = WORK_DETAIL.HTYPE_ID
AND HOUR_TYPE.HTYPE_ID = TIME_CODE.HTYPE_ID
-- AND hour_type.htype_name = 'UNPAID'
-- AND time_code.tcode_name = 'UAT'
AND WORK_DETAIL.WRKS_ID = WORK_SUMMARY.WRKS_ID
AND WORK_SUMMARY.EMP_ID = EMPLOYEE.EMP_ID
-- AND WORK_DETAIL.WRKD_WORK_DATE < SYSDATE
-- AND WORKBRAIN_TEAM.WBT_ID = EMPLOYEE_TEAM.WBT_ID
-- AND EMPLOYEE_TEAM.EMP_ID = EMPLOYEE.EMP_ID
AND WORK_DETAIL.JOB_ID = JOB.JOB_ID
AND EMPLOYEE.PAYGRP_ID = PAY_GROUP.PAYGRP_ID
GROUP BY EMPLOYEE.EMP_ID,EMPLOYEE.EMP_NAME
ORDER BY TOTAL_AMT|||That Works .Some how it still goes into a loop when I am using ROUND .I used TO_CHAR in fornt of both these variables & it then works .

Don't know why it does not work with a simple ROUND .I think I will need to check with the vendor .

Thanks a lot ,Andrewst ...looks like this should complete my query|||Also , how do I get the counts of employees with Total amount = 0 & the rest separately ?|||Originally posted by ritz1975
Also , how do I get the counts of employees with Total amount = 0 & the rest separately ?
Now that DOES need an inline view:

SELECT COUNT(*) FROM
( SELECT emp_id, SUM(...)
FROM ...
GROUP BY emp_id
HAVING SUM(...) = 0
)

Saturday, February 25, 2012

NEWBIE - Parameter @EmployeeName to select a particular employee OR all employees

I have an operational parameter in my SQL select statement, @.EmployeeName,
that will filter timecard data for a particular employee. When I am running
the query and it prompts me for @.EmployeeName, I would like the option of
putting in * or [ALL] or something of that nature to return all the timecard
data.
Is there a wildcard that I can put in my parameter prompt to return all the
records?
I will greatly appreciate any help you can offer on the subject. Thank you,
-Dave> that will filter timecard data for a particular employee. When I am
running
> the query and it prompts me for @.EmployeeName, I would like the option of
> putting in * or [ALL] or something of that nature to return all the
timecard
> data.
What prompts you for this? Can you not leave the parameter empty? How is
the stored procedure coded?
Typically, you can implement optional parameters, and when you call the
procedure, you can either include that parameter or not.
http://www.aspfaq.com/2348
I think you are being slowed down by the GUI tool you are using, not the
nature of parameters. Also, keep in mind that * is only a wildcard in DOS,
Microsoft Access and a few other places. SQL Server uses % and _ ...
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.|||I am using the Query Builder in VS.NET 2003, not a stored procedure. Do I
need to use a stored procedure to achieve this result?
When I leave the parameter empty, I get no results for my query.
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:%23RLQapIMFHA.1308@.TK2MSFTNGP15.phx.gbl...
> running
> timecard
> What prompts you for this? Can you not leave the parameter empty? How is
> the stored procedure coded?
> Typically, you can implement optional parameters, and when you call the
> procedure, you can either include that parameter or not.
> http://www.aspfaq.com/2348
> I think you are being slowed down by the GUI tool you are using, not the
> nature of parameters. Also, keep in mind that * is only a wildcard in
> DOS,
> Microsoft Access and a few other places. SQL Server uses % and _ ...
> --
> Please post DDL, sample data and desired results.
> See http://www.aspfaq.com/5006 for info.
>