Showing posts with label employee. Show all posts
Showing posts with label employee. 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

Monday, March 26, 2012

newbie question

The query:
Select FirstName, LastName
from AdventureWorks.Person.Contact PC
, AdventureWorks.HumanResources.Employee HRE
Where PC.ContactId = HRE.ContactId
AND LastName like 'Gilbert'
FOR XML auto, xmldata
The results:
<?xml version="1.0" encoding="UTF-8"?>
<Schema name="Schema1" xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<ElementType name="PC" content="empty" model="closed">
<AttributeType name="FirstName" dt:type="string" />
<AttributeType name="LastName" dt:type="string" />
<attribute type="FirstName" />
<attribute type="LastName" />
</ElementType>
</Schema>
<PC xmlns="x-schema:#Schema1" FirstName="Guy" LastName="Gilbert" />
Action:
Paste results into Altova XML Spy xml schema file type
or sml document file type
The Error:
File not well formatted.It seems to be two document elements issue.
Pohwan Han. Seoul. Have a nice day.
"mj" <mj@.discussions.microsoft.com> wrote in message
news:D479F5A7-235B-46D7-9E63-DA99F19964B1@.microsoft.com...
> The query:
> Select FirstName, LastName
> from AdventureWorks.Person.Contact PC
> , AdventureWorks.HumanResources.Employee HRE
> Where PC.ContactId = HRE.ContactId
> AND LastName like 'Gilbert'
> FOR XML auto, xmldata
> The results:
> <?xml version="1.0" encoding="UTF-8"?>
>
> <Schema name="Schema1" xmlns="urn:schemas-microsoft-com:xml-data"
> xmlns:dt="urn:schemas-microsoft-com:datatypes">
> <ElementType name="PC" content="empty" model="closed">
> <AttributeType name="FirstName" dt:type="string" />
> <AttributeType name="LastName" dt:type="string" />
> <attribute type="FirstName" />
> <attribute type="LastName" />
> </ElementType>
> </Schema>
> <PC xmlns="x-schema:#Schema1" FirstName="Guy" LastName="Gilbert" />
> Action:
> Paste results into Altova XML Spy xml schema file type
> or sml document file type
> The Error:
> File not well formatted.
>
>|||Woud it be possible to expand a littleon you're response please?
"Han" wrote:

> It seems to be two document elements issue.
> --
> Pohwan Han. Seoul. Have a nice day.
> "mj" <mj@.discussions.microsoft.com> wrote in message
> news:D479F5A7-235B-46D7-9E63-DA99F19964B1@.microsoft.com...
>|||A FOR XML query returns fragments and not whole documents. You may want to
specify the root property in the provider to get the document well formed
with a single root element.
Best regards
Michael
"mj" <mj@.discussions.microsoft.com> wrote in message
news:945BDD2C-918B-4D0E-A6E2-709A6190D32B@.microsoft.com...
> Woud it be possible to expand a littleon you're response please?
> "Han" wrote:
>

newbie question

The query:
Select FirstName, LastName
from AdventureWorks.Person.Contact PC
, AdventureWorks.HumanResources.Employee HRE
Where PC.ContactId = HRE.ContactId
AND LastName like 'Gilbert'
FOR XML auto, xmldata
The results:
<?xml version="1.0" encoding="UTF-8"?>
<Schema name="Schema1" xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<ElementType name="PC" content="empty" model="closed">
<AttributeType name="FirstName" dt:type="string" />
<AttributeType name="LastName" dt:type="string" />
<attribute type="FirstName" />
<attribute type="LastName" />
</ElementType>
</Schema>
<PC xmlns="x-schema:#Schema1" FirstName="Guy" LastName="Gilbert" />
Action:
Paste results into Altova XML Spy xml schema file type
or sml document file type
The Error:
File not well formatted.
It seems to be two document elements issue.
Pohwan Han. Seoul. Have a nice day.
"mj" <mj@.discussions.microsoft.com> wrote in message
news:D479F5A7-235B-46D7-9E63-DA99F19964B1@.microsoft.com...
> The query:
> Select FirstName, LastName
> from AdventureWorks.Person.Contact PC
> , AdventureWorks.HumanResources.Employee HRE
> Where PC.ContactId = HRE.ContactId
> AND LastName like 'Gilbert'
> FOR XML auto, xmldata
> The results:
> <?xml version="1.0" encoding="UTF-8"?>
>
> <Schema name="Schema1" xmlns="urn:schemas-microsoft-com:xml-data"
> xmlns:dt="urn:schemas-microsoft-com:datatypes">
> <ElementType name="PC" content="empty" model="closed">
> <AttributeType name="FirstName" dt:type="string" />
> <AttributeType name="LastName" dt:type="string" />
> <attribute type="FirstName" />
> <attribute type="LastName" />
> </ElementType>
> </Schema>
> <PC xmlns="x-schema:#Schema1" FirstName="Guy" LastName="Gilbert" />
> Action:
> Paste results into Altova XML Spy xml schema file type
> or sml document file type
> The Error:
> File not well formatted.
>
>
|||Woud it be possible to expand a littleon you're response please?
"Han" wrote:

> It seems to be two document elements issue.
> --
> Pohwan Han. Seoul. Have a nice day.
> "mj" <mj@.discussions.microsoft.com> wrote in message
> news:D479F5A7-235B-46D7-9E63-DA99F19964B1@.microsoft.com...
>
|||A FOR XML query returns fragments and not whole documents. You may want to
specify the root property in the provider to get the document well formed
with a single root element.
Best regards
Michael
"mj" <mj@.discussions.microsoft.com> wrote in message
news:945BDD2C-918B-4D0E-A6E2-709A6190D32B@.microsoft.com...[vbcol=seagreen]
> Woud it be possible to expand a littleon you're response please?
> "Han" wrote:

Monday, March 19, 2012

newbie needs help

Hello all, I'm learning SQL and need help with a query. I have a table that
stores employee ID and values per a given year. EmplID is stored in field 1
,
Yr1 val in field 2, Yr2 val in field 3... and so on up to any given number o
f
Yr fields. Not all of the Yr values exist for all Yr fields. I need to be
able to to pull the most recent value for a given row/record. So, for
instance, if EmplID ABCD stores the following:
EmplID Yr1 Yr2 Yr3 Yr4
ABCD 41 42 43 0
I need to pull 41 if Yr1 is the most recent year.
If Emplid EFGH stores the following:
EmplID Yr1 Yr2 Yr3 Yr4
EFGH 0 42 0 0
I need to pull 42, the Yr2 value, because no value exists for Yr1.
I am using SQL Server on a WinXP box. Any help would be greatly appreciated
.First of all, this is a poor design for a table. What are you doing,
continually adding new fields (we call them columns, or attributes) each
year? Better would be to have a column named "Year".
EmplID Year Value
ABCD 1 41
ABCD 2
You should, when possible, learn a bit about data modeling and
normalization... But
"kiloez" wrote:
> Hello all, I'm learning SQL and need help with a query. I have a table th
at
> stores employee ID and values per a given year. EmplID is stored in field
1,
> Yr1 val in field 2, Yr2 val in field 3... and so on up to any given number
of
> Yr fields. Not all of the Yr values exist for all Yr fields. I need to b
e
> able to to pull the most recent value for a given row/record. So, for
> instance, if EmplID ABCD stores the following:
> EmplID Yr1 Yr2 Yr3 Yr4
> ABCD 41 42 43 0
> I need to pull 41 if Yr1 is the most recent year.
> If Emplid EFGH stores the following:
> EmplID Yr1 Yr2 Yr3 Yr4
> EFGH 0 42 0 0
> I need to pull 42, the Yr2 value, because no value exists for Yr1.
> I am using SQL Server on a WinXP box. Any help would be greatly appreciated.[/col
or]|||Sorry submitted that before done...
First of all, this is a poor design for a table. What are you doing,
continually adding new fields (we call them columns, or attributes) each
year? Better would be to have a column named "Year".
EmplID Year Value
ABCD Yr1 41
ABCD Yr2 42
ABCD Yr3 43
ABCD Yr4 44
etc. .............
Second, what is Yr1, Yr2, Yr3, Yr4, mean ? Are these the actual column
names in your table? Do they map to actual years spmewhere else in your data
model?
When possible, you should learn a bit about data modeling and
normalization...
Given your problem, a solution based on the columns that exist in the table
right now would break when you add a new column for Yr5, unless the solution
was constructed to treat the "YrN" columns dynamically. That type of
solution would have to read system tables to determine which YR columns
existed, and then write dynamic sql to execute against the table.. A complex
but doable task. It would be much simpler (and therefore quicker more cost
effective) to restructure the data correctly.
"kiloez" wrote:
> Hello all, I'm learning SQL and need help with a query. I have a table th
at
> stores employee ID and values per a given year. EmplID is stored in field
1,
> Yr1 val in field 2, Yr2 val in field 3... and so on up to any given number
of
> Yr fields. Not all of the Yr values exist for all Yr fields. I need to b
e
> able to to pull the most recent value for a given row/record. So, for
> instance, if EmplID ABCD stores the following:
> EmplID Yr1 Yr2 Yr3 Yr4
> ABCD 41 42 43 0
> I need to pull 41 if Yr1 is the most recent year.
> If Emplid EFGH stores the following:
> EmplID Yr1 Yr2 Yr3 Yr4
> EFGH 0 42 0 0
> I need to pull 42, the Yr2 value, because no value exists for Yr1.
> I am using SQL Server on a WinXP box. Any help would be greatly appreciated.[/col
or]|||First off my dear friend, you might want to re-evaluate the database design.
You have just violated the second normal form (or is it the third? I get
) Anyways, the best solution would be to move your data to another
table and drop this table here.
I would suggest the following design for your table
CREATE TABLE Emp_Details (
EmpID int NOT NULL,
Year char(4) NOT NULL,
Value int NOT NULL DEFAULT 0
)
Then, populate it as follows:
INSERT INTO Emp_Details
SELECT EmplID, 'Yr1', Yr1
FROM Emp_Table
INSERT INTO Emp_Details
SELECT EmplID, 'Yr2', Yr2
FROM Emp_Table
INSERT INTO Emp_Details
SELECT EmplID, 'Yr3', Yr3
FROM Emp_Table
INSERT INTO Emp_Details
SELECT EmplID, 'Yr4', Yr4
FROM Emp_Table
and so on...
now you have a sensible looking table. you may want to drop your old table
and rename this table. Let everyone know that you have just got some sensibl
e
table design done and that the applications need to change the way they
access data.
Once this is done, you can run the following query:
SELECT Emp_ID, MAX(Year), Value
FROM Emp_Details
WHERE (Value <> 0)
GROUP BY Emp_ID, Value
--that said, if you want a quick fix or boss is not willing to let go of
his ideas of 3NF, you can run this query:
SELECT EmplID,
CASE
WHEN (Yr1 <> 0) THEN Yr1
ELSE
CASE
WHEN (Yr2 <> 0) THEN Yr2
ELSE
CASE
WHEN (Yr3 <> 0) THEN Yr3
ELSE Yr4
END CASE
END CASE
END CASE
FROM Empl_Details
Hope that helps,
Aneesh.
"kiloez" wrote:
> Hello all, I'm learning SQL and need help with a query. I have a table th
at
> stores employee ID and values per a given year. EmplID is stored in field
1,
> Yr1 val in field 2, Yr2 val in field 3... and so on up to any given number
of
> Yr fields. Not all of the Yr values exist for all Yr fields. I need to b
e
> able to to pull the most recent value for a given row/record. So, for
> instance, if EmplID ABCD stores the following:
> EmplID Yr1 Yr2 Yr3 Yr4
> ABCD 41 42 43 0
> I need to pull 41 if Yr1 is the most recent year.
> If Emplid EFGH stores the following:
> EmplID Yr1 Yr2 Yr3 Yr4
> EFGH 0 42 0 0
> I need to pull 42, the Yr2 value, because no value exists for Yr1.
> I am using SQL Server on a WinXP box. Any help would be greatly appreciated.[/col
or]|||Thanks for the help guys. I had nothing to do with the design and
development of the DB. I was only asked to query some of the tables.
Aneesh, the quick fix was perfect for what I was looking to accomplish.
Worked out just fine.
Many thanks,
kiloez
"Aneesh Aravind" wrote:
> First off my dear friend, you might want to re-evaluate the database desig
n.
> You have just violated the second normal form (or is it the third? I get
> ) Anyways, the best solution would be to move your data to another
> table and drop this table here.
> I would suggest the following design for your table
> CREATE TABLE Emp_Details (
> EmpID int NOT NULL,
> Year char(4) NOT NULL,
> Value int NOT NULL DEFAULT 0
> )
> Then, populate it as follows:
> INSERT INTO Emp_Details
> SELECT EmplID, 'Yr1', Yr1
> FROM Emp_Table
> INSERT INTO Emp_Details
> SELECT EmplID, 'Yr2', Yr2
> FROM Emp_Table
> INSERT INTO Emp_Details
> SELECT EmplID, 'Yr3', Yr3
> FROM Emp_Table
> INSERT INTO Emp_Details
> SELECT EmplID, 'Yr4', Yr4
> FROM Emp_Table
> and so on...
> now you have a sensible looking table. you may want to drop your old table
> and rename this table. Let everyone know that you have just got some sensi
ble
> table design done and that the applications need to change the way they
> access data.
> Once this is done, you can run the following query:
> SELECT Emp_ID, MAX(Year), Value
> FROM Emp_Details
> WHERE (Value <> 0)
> GROUP BY Emp_ID, Value
> --that said, if you want a quick fix or boss is not willing to let go of
> his ideas of 3NF, you can run this query:
> SELECT EmplID,
> CASE
> WHEN (Yr1 <> 0) THEN Yr1
> ELSE
> CASE
> WHEN (Yr2 <> 0) THEN Yr2
> ELSE
> CASE
> WHEN (Yr3 <> 0) THEN Yr3
> ELSE Yr4
> END CASE
> END CASE
> END CASE
> FROM Empl_Details
> Hope that helps,
> Aneesh.
> "kiloez" wrote:
>

Wednesday, March 7, 2012

Newbie : Need Help in joining Multiple tables

I am using a query to get data about temp job & temp rates for an employee database. Problem is this query pulls up two records with different rates for the same work period. THE JOB_RATE table has two different job rates with different JOBRATE_EFFECTIVE_RATE . What candition should I add in this query so that it pulls up the Jobrate applicable to that particular WORKDATE & not all JOBRATES .

i.e,
say if Jobrate = 10 on 1-Dec-2002 & later revised to Jobrate =20 effective 1-Jan-2003, then for a particular workdate 16-Dec-02 ,
the report should display one record with Temp_rate= 10 instadof two records with diffenrent rates, other data being same

select EMPLOYEE.EMP_ID,
Job.Job_name Temp_job,
Job_Rate.Jobrate_Rate Temp_Rate,
To_Char(Work_Detail.Wrkd_Work_Date,'MM-DD-YYYY') WorkDate ,
To_Char(Work_Detail.wrkd_Start_Time,'HH24:MI') BeginTime ,
To_Char(Work_Detail.wrkd_End_time,'HH24:MI') EndTime
from Employee , Job, Job_Rate ,Work_Detail,Work_Summary
where EMPLOYEE.EMP_ID = WORK_SUMMARY.EMP_ID
AND WORK_SUMMARY.WRKS_ID = WORK_DETAIL.WRKS_ID
AND WORK_DETAIL.JOB_ID = JOB.JOB_ID
AND JOB.JOB_ID = Job_Rate.Job_IdOriginally posted by ritz1975
I am using a query to get data about temp job & temp rates for an employee database. Problem is this query pulls up two records with different rates for the same work period. THE JOB_RATE table has two different job rates with different JOBRATE_EFFECTIVE_RATE . What candition should I add in this query so that it pulls up the Jobrate applicable to that particular WORKDATE & not all JOBRATES .

i.e,
say if Jobrate = 10 on 1-Dec-2002 & later revised to Jobrate =20 effective 1-Jan-2003, then for a particular workdate 16-Dec-02 ,
the report should display one record with Temp_rate= 10 instadof two records with diffenrent rates, other data being same

select EMPLOYEE.EMP_ID,
Job.Job_name Temp_job,
Job_Rate.Jobrate_Rate Temp_Rate,
To_Char(Work_Detail.Wrkd_Work_Date,'MM-DD-YYYY') WorkDate ,
To_Char(Work_Detail.wrkd_Start_Time,'HH24:MI') BeginTime ,
To_Char(Work_Detail.wrkd_End_time,'HH24:MI') EndTime
from Employee , Job, Job_Rate ,Work_Detail,Work_Summary
where EMPLOYEE.EMP_ID = WORK_SUMMARY.EMP_ID
AND WORK_SUMMARY.WRKS_ID = WORK_DETAIL.WRKS_ID
AND WORK_DETAIL.JOB_ID = JOB.JOB_ID
AND JOB.JOB_ID = Job_Rate.Job_Id
You need to say:

AND job_rate.effective_date =
( SELECT MAX(jr.effective_date)
FROM job_rate jr
WHERE jr.effective_date <= Work_Detail.Wrkd_Work_Date
AND jr.job_id = job.job_id)

It is common to have a job_rate.end_date column to overcome this, so that the condition is simply:

AND Work_Detail.Wrkd_Work_Date BETWEEN job_rate.effective_date AND job_rate.end_date

This simplifies the query, but adds complication to the rate maintenance functionality.|||Thanks Andrewst .

The query has worked & I am satisfied after testing it .Thanks a lot for the help.

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.
>