Stored Procedure- Multil level employee hierarchy in the same row
I have an employee table where I have employee details which includes the following properties:
EmployeeID, EmployeeName, ManagerID, DesignationCode.
ManagerID maps to EmployeeID in the Emp table. DesignationCode is to identify the employee designation.
The topmost person of the organization could be identified by : whose DesignationCode is 'XX' and ManagerID=EmplyeeID.
Here, 'XX' is fixed and will not change.
Also, we know there could be a maximum of 10 level for each hierarchy.
Example: Employee1 reports to Manager1 who reports to Manager2 who reports to Manager 3 ..... who reports to ManagerN.
I need to pull a hierarchy in the below format:
EmpName MgrName0 MagrName1 MgrName2 ..........MgrName7 MgrName8
MgrName9
SAMRAT
XXX XXX
SUDHAKAR
XXX XXX XXX
SATESWAR
XXX XXX
SRINI XXX XXX
XXX XXX XXX
IMPORTANT POINT: We need to identify the reporting hierarchy level for each employee's manager and then place the manager names accordingly based on the columns.
Example:
If an employee's manager has only 1 reporting manager(who is at top level), then he would be placed at the column "ManagerName8" and ManageName9 would be the topmost employee of the organization
In short, we need to identify the reporting level at which the employees manager belongs and then start filling the columns values for that row ( employee details)
I am stuck and unable to do the same. Please help.
Thank you.
Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on SQL forums.
>> I have an employee table where I have employee details <<
An SQL programmer would have a Personnel table instead. What you have said is that you have only one employee!
>> which includes the following properties:
emp_id, emp_name, manager_emp_id, designation_code.<<
Why do you think that a manager is an attribute of an employee? This is absurd! They have a relationship; where is the table that models that relationship? It is missing from this non-normalized, improperly designed table.
There are many ways to represent a tree or hierarchy in SQL. YOU are trying to use an adjacency list model. This approach will wind up with really ugly code -- CTEs hiding recursive procedures, horrible cycle prevention code, etc.
Another way of representing trees is to show them as nested sets.
Since SQL is a set oriented language, this is a better model than the usual adjacency list approach you see in most text books. Let us define a simple OrgChart table like this.
CREATE TABLE OrgChart
(emp_name CHAR(10) NOT NULL PRIMARY KEY,
lft INTEGER NOT NULL UNIQUE CHECK (lft > 0),
rgt INTEGER NOT NULL UNIQUE CHECK (rgt > 1),
CONSTRAINT order_okay CHECK (lft < rgt));
OrgChart
emp_name lft rgt
======================
'Albert' 1 12
'Bert' 2 3
'Chuck' 4 11
'Donna' 5 6
'Eddie' 7 8
'Fred' 9 10
The (lft, rgt) pairs are like tags in a mark-up language, or parens in algebra, BEGIN-END blocks in Algol-family programming languages, etc. -- they bracket a sub-set. This is a set-oriented approach to trees in a set-oriented language.
The organizational chart would look like this as a directed graph:
Albert (1, 12)
Bert (2, 3) Chuck (4, 11)
/ | \
/ | \
/ | \
/ | \
Donna (5, 6) Eddie (7, 8) Fred (9, 10)
The adjacency list table is denormalized in several ways. We are modeling both the Personnel and the Organizational chart in one table. But for the sake of saving space, pretend that the names are job titles and that we have another table which describes the
Personnel that hold those positions.
Another problem with the adjacency list model is that the boss_emp_name and employee columns are the same kind of thing (i.e. identifiers of personnel), and therefore should be shown in only one column in a normalized table. To prove that this is not
normalized, assume that "Chuck" changes his name to "Charles"; you have to change his name in both columns and several places. The defining characteristic of a normalized table is that you have one fact, one place, one time.
The final problem is that the adjacency list model does not model subordination. Authority flows downhill in a hierarchy, but If I fire Chuck, I disconnect all of his subordinates from Albert. There are situations (i.e. water pipes) where this is true, but
that is not the expected situation in this case.
To show a tree as nested sets, replace the nodes with ovals, and then nest subordinate ovals inside each other. The root will be the largest oval and will contain every other node. The leaf nodes will be the innermost ovals with nothing else inside them
and the nesting will show the hierarchical relationship. The (lft, rgt) columns (I cannot use the reserved words LEFT and RIGHT in SQL) are what show the nesting. This is like XML, HTML or parentheses.
At this point, the boss_emp_name column is both redundant and denormalized, so it can be dropped. Also, note that the tree structure can be kept in one table and all the information about a node can be put in a second table and they can be joined on employee
number for queries.
To convert the graph into a nested sets model think of a little worm crawling along the tree. The worm starts at the top, the root, makes a complete trip around the tree. When he comes to a node, he puts a number in the cell on the side that he is visiting
and increments his counter. Each node will get two numbers, one of the right side and one for the left. Computer Science majors will recognize this as a modified preorder tree traversal algorithm. Finally, drop the unneeded OrgChart.boss_emp_name column
which used to represent the edges of a graph.
This has some predictable results that we can use for building queries. The root is always (left = 1, right = 2 * (SELECT COUNT(*) FROM TreeTable)); leaf nodes always have (left + 1 = right); subtrees are defined by the BETWEEN predicate; etc. Here are
two common queries which can be used to build others:
1. An employee and all their Supervisors, no matter how deep the tree.
SELECT O2.*
FROM OrgChart AS O1, OrgChart AS O2
WHERE O1.lft BETWEEN O2.lft AND O2.rgt
AND O1.emp_name = :in_emp_name;
2. The employee and all their subordinates. There is a nice symmetry here.
SELECT O1.*
FROM OrgChart AS O1, OrgChart AS O2
WHERE O1.lft BETWEEN O2.lft AND O2.rgt
AND O2.emp_name = :in_emp_name;
3. Add a GROUP BY and aggregate functions to these basic queries and you have hierarchical reports. For example, the total salaries which each employee controls:
SELECT O2.emp_name, SUM(S1.salary_amt)
FROM OrgChart AS O1, OrgChart AS O2,
Salaries AS S1
WHERE O1.lft BETWEEN O2.lft AND O2.rgt
AND S1.emp_name = O2.emp_name
GROUP BY O2.emp_name;
4. To find the level and the size of the subtree rooted at each emp_name, so you can print the tree as an indented listing.
SELECT O1.emp_name,
SUM(CASE WHEN O2.lft BETWEEN O1.lft AND O1.rgt
THEN O2.sale_amt ELSE 0.00 END) AS sale_amt_tot,
SUM(CASE WHEN O2.lft BETWEEN O1.lft AND O1.rgt
THEN 1 ELSE 0 END) AS subtree_size,
SUM(CASE WHEN O1.lft BETWEEN O2.lft AND O2.rgt
THEN 1 ELSE 0 END) AS lvl
FROM OrgChart AS O1, OrgChart AS O2
GROUP BY O1.emp_name;
5. The nested set model has an implied ordering of siblings which the adjacency list model does not. To insert a new node, G1, under part G. We can insert one node at a time like this:
BEGIN ATOMIC
DECLARE rightmost_spread INTEGER;
SET rightmost_spread
= (SELECT rgt
FROM Frammis
WHERE part = 'G');
UPDATE Frammis
SET lft = CASE WHEN lft > rightmost_spread
THEN lft + 2
ELSE lft END,
rgt = CASE WHEN rgt >= rightmost_spread
THEN rgt + 2
ELSE rgt END
WHERE rgt >= rightmost_spread;
INSERT INTO Frammis (part, lft, rgt)
VALUES ('G1', rightmost_spread, (rightmost_spread + 1));
COMMIT WORK;
END;
The idea is to spread the (lft, rgt) numbers after the youngest child of the parent, G in this case, over by two to make room for the new addition, G1. This procedure will add the new node to the rightmost child position, which helps to preserve the idea
of an age order among the siblings.
6. To convert a nested sets model into an adjacency list model:
SELECT B.emp_name AS boss_emp_name, E.emp_name
FROM OrgChart AS E
LEFT OUTER JOIN
OrgChart AS B
ON B.lft
= (SELECT MAX(lft)
FROM OrgChart AS S
WHERE E.lft > S.lft
AND E.lft < S.rgt);
7. To find the immediate parent of a node:
SELECT MAX(P2.lft), MIN(P2.rgt)
FROM Personnel AS P1, Personnel AS P2
WHERE P1.lft BETWEEN P2.lft AND P2.rgt
AND P1.emp_name = @my_emp_name;
I have a book on TREES & HIERARCHIES IN SQL which you can get at Amazon.com right now. It has a lot of other programming idioms for nested sets, like levels, structural comparisons, re-arrangement procedures, etc.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL
Similar Messages
-
I've been trying to call a stored procedure through Entity Framework and WCF Data Services (OData). It returns an entity not a complex type. Following walkthroughs found all over the web, I came up with this code inside my service:
[WebGet]
public IQueryable<Entity> GetEntitiesByParameterId(int parameterId)
return CurrentDataSource.GetEntitiesByParameterId(parameterId).AsQueryable();
Calling the proc this way: ~WcfService.svc/GetEntitiesByParameterId?parameterId=1 executes
the stored procedure and returns entities that should be returned. No problem there.
Everything works well until I try to use $select OData option ie. ~WcfService.svc/GetEntitiesByParameterId?parameterId=1&$select=name.
Upon debugging, the method above runs without any error but it returns an Operation could destabilize the runtime error upon reaching the
client. After so much research, apparently it is a very general error pointing to a lot of different causes. I haven't found one that really matches my particular problem. Closest are
http://stackoverflow.com/questions/378895/operation-could-destabilize-the-runtime
https://social.msdn.microsoft.com/Forums/en-US/d2fb4767-dc09-4879-a62a-5b2ce96c4465/for-some-columns-entity-properties-executestorequery-failed-with-error-operation-could?forum=adodotnetdataservices
but none of the solutions worked on my end.
Also, from the second article above:
This is a known limitation of WCF DS. ...
Second is that some of the queries won't work correctly because LINQ to EF needs little different LINQ expressions than LINQ to Objects in some cases. Which is the problem you're seeing.
It has been posted on 2012. If it its true, are there still no updates on this? And is there any other workaround to get the $select working on the stored proc call?
What works:
~WcfService.svc/GetEntitiesByParameterId?parameterId=1
~WcfService.svc/GetEntitiesByParameterId?parameterId=1&$top=1
~WcfService.svc/GetEntitiesByParameterId?parameterId=1&$skip-5
~WcfService.svc/GetEntitiesByParameterId?parameterId=1&$filter={filter query}
~WcfService.svc/GetEntitiesByParameterId?parameterId=1&$expand=SomeNavigationProperty
What doesn't work:
~WcfService.svc/GetEntitiesByParameterId?parameterId=1&$select=name
Tech details:
EntityFramework 5, WCF Data Service 5.0, OData V3
*I've also tried upgrading to EF6 and WCF 5.6.2 and it still didn't work.
Any help would be appreciated. Thanks!Someone from SO replied to my question there and said that $select is still not supported though I couldn't find any definitive documentation about it.
From what I gather and observed, $select breaks the stored procedure call because it tries to alter the data shape already gotten from the database and attempts to return a dynamic entity instead. Something about the stored proc returning an ObjectResult might
be messing it up. As I have said, these are merely my observations.
Workaround: I found a simple and elegant workaround for it though. Since my stored procedures are only getting data from the database and does
not alter data in any way (INSERT, UPDATE, DELETE), I tried using table-valued functions that returns a table equivalent to the entity on my EF. I've found that calling this function on the Service Operation method returns an IQueryable<Entity> which
is basically what is needed. $select also works now and so does other OData query options.
Steps:
Create a function on the database
Update EDMX -> Add function
Add new Function Import with Entity return type
Create service operation in WCF Data Service that calls CurrentDataSource.<FunctionName>()
Test in fiddler.
CODES
Database Function:
CREATE FUNCTION GetEntities(@parameter)
RETURN @entites TABLE(
[Id] [int],
[Name] [nvarchar](100),
AS
BEGIN
INSERT INTO @entities
SELECT [Id], [Name], ... FROM [EntityTable]
RETURN
END
WCF:
[WebGet]
public IQueryable<Entity> GetEntity(int parameter)
return CurrentDataSource.GetEntity(parameter);
It doesn't really solve the stored procedure problem but I'm marking this as answer until someone can provide a better one as it does solve what I'm trying to do.
Hope this helps others too. :) -
How to list the employees working under one manager in the same row.
Hi,
my emp table has the following data.
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
I want to group all the employees under one manager and list their names in the same row. IS that possible. When i tried the query below,
select mgr, count(*) employees from emp where mgr is not null group by mgr, ename;
I got the result as
MGR EMPLOYEES
7566 2
7698 6
7782 1
7788 1
7839 3
7902 1
Additionally, would I be able to display the names of the employees under one manager in a row? or atleast in some other way? Pls share your ideas.A summary of different string aggregation techniques can be found here
http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php -
If employee id is the same should not print on the xml publisher report
Hi Dear,
I met with one problem and needs some suggestion on the best approach on it. It is a xml publisher report.
We have multiple rows for the same employee , but for the same employee only the first row needs to print the emplid.
Do we need to write the if statement , how to get the value of the last row emplid ?
For example :
EMPLID EMP_RCD STATE
1001 0 CA
1 TX
Any suggestion is appreciated.
Thanks,
DennisI understand your requirement is as follows:
Requirement:_
The data is this ->
EMPLID COLUMN 1 COLUMN 2 COLUMN 3
EMPLID_01 DATA_01_01 DATA_02_01 DATA_03_01
EMPLID_01 DATA_01_02 DATA_02_02 DATA_03_02
EMPLID_01 DATA_01_03 DATA_02_03 DATA_03_03
EMPLID_02 DATA_01_04 DATA_02_04 DATA_03_04
And you need report in this format:
EMPLID_01 DATA_01_01 DATA_02_01 DATA_03_01
DATA_01_02 DATA_02_02 DATA_03_02
DATA_01_03 DATA_02_03 DATA_03_03
EMPLID_02 DATA_01_03 DATA_02_04 DATA_03_04
Solution:_
If my understanding is correct, then you can make use of variables
at start of template set the variable to 0
*<?xdoxslt:set_variable($_XDOCTX,'PREV_EMPLID',0)?>*
at the end of each data row, reset the variable
*<?xdoxslt:set_variable($_XDOCTX,'PREV_EMPLID',EMPLID)?>*
while printing emplid in that row use IF condition
*<?if:(xdoxslt:get_variable($_XDOCTX, 'PREV_EMPLID'))!=EMPLID?>*
The above If condition will print emplid on the row only when there is change in EMPLID, so effectively printing emplid only on the 1st row of data for each employee id.
Also, you need to ensure that you group by employee id before you print each row.
Let me know if this works for you. -
Gantt view - multiple dates in the same row
Hi,
I created gantt view showing employees' vacations. Some of them have their holidays split into several dates (periods). How can I show those multiple dates in the same row in the gantt view? I can only show start date and end date of one vacation, but would
like to enter multiple periods to be shown in the gantt view, in the same row.
Thanks.You can't using the OOTB gantt chart so you would have to look at custom development or 3rd party web parts.
Such as (blatant plug but it directly answers the OP question) my own companies Planner web part.
http://www.pentalogic.net/sharepoint-products/planner
The By Category view puts timelines on the same row so its ideal for things like vacation planning, room booking etc.
This page shows it in use.
http://blog.pentalogic.net/2010/08/sharepoint-staff-vacation-planner-absence-wall-chart-dashboard/ -
I want to have about five to ten bookmark icons in the same row as the search and address bar. So i use Customize... and I put the bookmark bar on the same line. I leave the "Name"-textbox in every bookmark blank so that only the icons appear.
However, only two icons appear and the rest are displayed in a drop down menu from an arrow you click.
I don't need the address bar to take 70% of the screen. I don't want the bookmark bar to use an extra row. I just want to have five to ten bookmark icons next to my address and search bar. Is this possible?What do you mean with "Save passwords" checkbox?
Is that box provided by an extension?
Can you attach a screenshot?
*http://en.wikipedia.org/wiki/Screenshot
*https://support.mozilla.org/kb/how-do-i-create-screenshot-my-problem
Use a compressed image type like PNG or JPG to save the screenshot.
Websites remembering you and automatically log you on is stored in a cookie.
* Create an allow cookie exception (Tools > Options > Privacy > Cookies: Exceptions) to keep such a cookie, especially for secure websites and if cookies expire when Firefox is closed.
Make sure that you do not run Firefox in Private Browsing mode.
* https://support.mozilla.com/kb/Private+Browsing
Do not use Clear Recent History to clear the "Cookies" and the "Site Preferences"
* https://support.mozilla.com/kb/Clear+Recent+History
Clearing "Site Preferences" clears all exceptions for cookies, images, pop-up windows, software installation, and passwords. -
How can I sum every other column in the same row?
I have, for each employee, two columns: Planned and Worked.
I would like to sum the values in each Planned column. There are 25 employees, each with their own Planned and Worked columns, on the same row.
How can I do a SUM of every other column, starting with Planned?
Thank you.Thank you, Yellowbox!
The exact formula didn't work; however, it gave me a precise path to follow and come up with this: =SUMIF(E2:BB2,"=Planned",E3:BB3)
Week
Ending Date
Planned Subtotal
Worked Subtotal
Employee1
Employee2
Employee3
Planned
Worked
Planned
Worked
Planned
Worked
1
01/04/2014
120
40
38
40
44
40
50
2
01/11/2014
If not for your starting point, I'd have wasted many more hours on this.
Thanks again!
BB -
Insert a field and update the same row.
Hi,
I am inserting a value in a row.
And later within a cursor loop I am trying to update the same row. But it is not working....
CREATE OR REPLACE procedure Del_Note_stage
Is
v_delNote Delivery_Note.Delivery_Note_id%type;
Cursor C1 is Select Heading_Name,File_Data from Sqlload_Stage;
Begin
dbms_output.put_line('i am here a ');
Select Delivery_Note_Id_Seq.nextval into v_delNote from dual;
Insert into DELIVERY_NOTE_STAGING(Delivery_Note_ID,LUT,LUB,PROCESSED) Values(v_delNote,sysdate,'Config','N');
commit;
dbms_output.put_line('i am here b'||v_delNote);
For sqlload_rec in C1
Loop
dbms_output.put_line(sqlload_rec.Heading_Name);
dbms_output.put_line('Del Note Id is :'||v_delNote);
update DELIVERY_NOTE_STAGING set deployed_by='TOM' where delivery_note_id=v_delNote;
End loop;
End;But it is not working....Why not?
Please read: http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
Why are you updating after inserting?
Just add deployed_by to the insert statement, or use a default value for that column.
Also you don't need to select your Delivery_Note_Id_Seq.nextval from dual, just use it in your insert statement.
Something like:
Insert into DELIVERY_NOTE_STAGING(Delivery_Note_ID,LUT,LUB,PROCESSED,deployed_by )
Values( Delivery_Note_Id_Seq.nextval,sysdate,'Config','N', 'TOM' /*or USER*/); -
How to display current postion and previous position in the same row?
I need to produce a promotions/transfer report that gives the employee's current position as well as his/her previous position in the same row.
for example:
Employee current position current organization current company previous postion previous organization previous company
Jane Smith Executive PA ZYX ltd Harmony personal assistant ABC ltd Yahoo
I am using the per_all_people_f, per_all_assignments_f, per_periods_of_service, hr.all_organization_units, per_all_positions tables
Somehow i cannot manage to display the previous position. I can only get so far to display the current postions
Any ideas? here is the full code
--this query gives current info
select ppf.employee_number, ppf.full_name
, (DECODE (ppf.sex, 'M', 'Male', 'F', 'Female') ) gender
, (DECODE (ppf.per_information4
,'01', 'Indian'
,'02', 'African'
,'03', 'Coloured'
,'04', 'White') ) race
, ppf.ORIGINAL_DATE_OF_HIRE
, paf.EFFECTIVE_START_DATE current_postion_start_date
, RTRIM (SUBSTR (hpt.NAME, 1, INSTR (hpt.NAME, ';') ),';')Current_Position
, ho.name Current_Organization
, xx_return_structures.xx_return_company_name
(paf.person_id,
paf.effective_start_date
) current_company
from per_all_assignments_f paf,
hr_all_positions_f_tl hpt,
hr_all_organization_units_tl ho,
per_all_people_f ppf
--where paf.person_id = 16170
and paf.POSITION_ID=hpt.POSITION_ID
and paf.ASSIGNMENT_NUMBER is not null
and ho.organization_id = paf.organization_id
and ppf.person_id=paf.person_id
and paf.EFFECTIVE_START_DATE between ppf.EFFECTIVE_START_DATE and ppf.EFFECTIVE_END_DATE
order by paf.EFFECTIVE_START_DATE
--this query gives previous position, organization and company
select ass.EFFECTIVE_START_DATE
, RTRIM (SUBSTR (hpt.NAME, 1, INSTR (hpt.NAME, ';') ),';')Previous_Position
, ho.NAME previous_organization
, xx_return_structures.xx_return_company_name
(paf.person_id,
paf.effective_start_date
) previous_company
from per_all_assignments_f paf, hr_all_positions_f_tl hpt, hr_all_organization_units_tl ho
where paf.person_id = 16170
and paf.EFFECTIVE_START_DATE not in (select max(paf.EFFECTIVE_START_DATE)
f rom per_all_assignments_f paf
where ass.person_id = 16170)
and paf.PRIMARY_FLAG ='Y'
and paf.POSITION_ID=hpt.POSITION_ID
and paf.ORGANIZATION_ID=ho.ORGANIZATION_IDOk so here is my problem. The current position display 3 times. The rest is correct. it only display once. Any ideas on how to get rid of the 2 extra rows that is being displayed with the current position?? I only need the current position to display once with the previous position info.
select distinct pvs.person_id,
peo.EMPLOYEE_NUMBER empno,
peo.FULL_NAME,
(DECODE (peo.sex, 'M', 'Male', 'F', 'Female') ) gender,
(DECODE (peo.per_information4
,'01', 'Indian'
,'02', 'African'
,'03', 'Coloured'
,'04', 'White') ) race,
peo.ORIGINAL_DATE_OF_HIRE,
pvs.EFFECTIVE_START_DATE curr_start_date,
RTRIM (SUBSTR (pvs.job, 1, INSTR (pvs.job, ';') ) ,';') current_position,
pvs.ORGANIZATION current_organization,
substr(pvs.PAYROLL,5)current_company,
a1.previous_position,
a1.previous_organisation,
a1.previous_company
from per_periods_of_work_v pv,
per_assignments_v2 pvs,
per_all_people_f peo,(select distinct RTRIM (SUBSTR (pvs.job, 1, INSTR (pvs.job, ';') ) ,';') previous_position,
pvs.ORGANIZATION previous_organisation,
substr(pvs.PAYROLL,5)previous_company,
pvs.job_id job_id,
pvs.organization_id,
pvs.position_id,
pvs.location_id,
pvs.PERSON_ID,
pvs.PEOPLE_GROUP_ID,
pvs.EFFECTIVE_END_DATE,
pvs.EFFECTIVE_START_DATE
from per_assignments_v2 pvs
where sysdate > pvs.EFFECTIVE_END_DATE
and pvs.person_id=4723
)a1
where peo.person_id = pvs.person_id
and pvs.person_id = pv.person_id
and a1.person_id = pvs.person_id
and pvs.EFFECTIVE_START_DATE between peo.EFFECTIVE_START_DATE and peo.EFFECTIVE_END_DATE
and pvs.PEOPLE_GROUP_ID <> a1.people_group_id
and pvs.JOB_ID <> a1.job_id
and pvs.ORGANIZATION_ID <> a1.organization_id
and pvs.position_id <> a1.position_id activating this elimnates 1-Feb-2008 info
and pvs.effective_start_date -1 = a1.effective_end_date activating this eliminates 1-feb-2008, 1-jul-2006, 1-april-1996 info
and pv.person_id = 4723
order by pvs.effective_start_date desc -
Hi there,
I am a beginner in Visual Basic Express 2010. I have a Point of Sale program that uses DataGridView to display records from an external microsoft access
database using the fillby query.
It works, but it repopulates the same row each time, but i want to be able to display multiple records at the same time, a new row should be filled for
each click of the fillby button.
also I want to be able to delete any records if the customer suddenly decides to not buy an item after it has already been entered.
so actually 2 questions here:
1. how to populate a new row for each click of the fillby button
2. how to delete records from data grid view after an item has been entered
Thanks
VishwasHello,
The FillBy method loads data according to what the results are from the SELECT statement, so if there is one row then you get one row in the DataGridView, have two rows then two rows show up.
Some examples
Form load populates our dataset with all data as it was defined with a plain SELECT statement. Button1 loads via a query I created after the fact to filter on a column, the next button adds a new row to the existing data. When adding a new row it is appended
to the current data displayed and the primary key is a negative value but the new key is shown after pressing the save button on the BindingNavigator or there are other ways to get the new key by manually adding the row to the backend table bypassing the Adapter.
The following article with code shows this but does not address adapters.
Conceptually speaking the code in the second code block shows how to get the new key
Public Class Form1
Private Sub StudentsBindingNavigatorSaveItem_Click(
sender As Object, e As EventArgs) Handles StudentsBindingNavigatorSaveItem.Click
Me.Validate()
Me.StudentsBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.MyDataSet)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'MyDataSet.Students' table. You can move, or remove it, as needed.
Me.StudentsTableAdapter.Fill(Me.MyDataSet.Students)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.StudentsTableAdapter.FillBy(Me.MyDataSet.Students, ComboBox1.Text)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.MyDataSet.Students.AddStudentsRow("Jane", "Adams", "Female")
End Sub
End Class
Get new key taken from
this article.
Public Function AddNewRow(ByVal sender As Customer, ByRef Identfier As Integer) As Boolean
Dim Success As Boolean = True
Try
Using cn As New OleDb.OleDbConnection With {.ConnectionString = Builder.ConnectionString}
Using cmd As New OleDb.OleDbCommand With {.Connection = cn}
cmd.CommandText = InsertStatement
cmd.Parameters.AddWithValue("@CompanyName", sender.CompanyName)
cmd.Parameters.AddWithValue("@ContactName", sender.ContactName)
cmd.Parameters.AddWithValue("@ContactTitle", sender.ContactTitle)
cn.Open()
cmd.ExecuteNonQuery()
cmd.CommandText = "Select @@Identity"
Identfier = CInt(cmd.ExecuteScalar)
End Using
End Using
Catch ex As Exception
Success = False
End Try
Return Success
End Function
In closing I have not given you a solution but hopefully given you some stuff/logic to assist with this issue, if not perhaps I missed what you want conceptually speaking.
Additional resources
http://msdn.microsoft.com/en-us/library/fxsa23t6.aspx
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. -
Is there a way to add a column after a filled DataTable from SQL with the same rows?
My problem is that not to add rows like filled by SQLDataAdapter at the same row in DataGridView. How to make that? I showed below the details with my code also a screen shot, which shows the rows differences from the origin one.
I don't want to add an expression as column behave in my sql script to get what I need with query result. I don't want to obtain that way.
using (SqlConnection c = new SqlConnection(ConnStrMSSQL))
c.Open();
// 2
// Create new DataAdapter
using (SqlDataAdapter a = new SqlDataAdapter("SELECT SIPNO, SERINO, TARIH FROM SNOHAREKETLER WHERE Cast(TARIH as DATE) BETWEEN '2015/03/20' AND '2015/03/20' AND (TEZNO = 'T23' OR TEZNO = 'T31') AND CIKTI is null", c))
// 3
// Use DataAdapter to fill DataTable
DataTable t = new DataTable();
a.Fill(t);
t.Columns.Add("MyColumn", typeof(string));
DataRow workRow;
int iGetCount = t.Rows.Count;
for (int i = 0; i <= iGetCount - 1; i++)
workRow = t.NewRow();
workRow["MyColumn"] = i;
t.Rows.Add(workRow);
dataGridView1.DataSource = t;The extra column isn't applied to only certain rows. The columns of a table identify what data each row will contain. Hence adding a column to the table automatically adds them to the rows. What you're seeing is that all the initial rows
aren't being assigned a value so they retain their default value of null. Later you enumerate the rows of the existing table and call AddRow which adds new rows. This isn't adding columns, but rows.
To generate values for the existing rows you should ideally simply pass the data back from the database. DT computed columns can be difficult to set up as it is limited to what it can do. If you want to use a computed column on the Datatable
itself then define the column as a computed column and every row will calculate its own value.
DataTable data = GetData();
//Add elapsed time column
var col = new DataColumn("ElapsedTime", typeof(TimeSpan), "expr");
data.Columns.Add(col);
dataGridView1.DataSource = data;
The issue you will run into however is that calculating a diff on DateTime doesn't work in a computed column as the expression doesn't support the necessary functions. You can google for how people solved this if you are interested in alternatives.
Most people just tend to add the column and then hook into the various change events to update the value as needed. -
Data from two tables in the same row in XML transformation
Hi,
I am using XML transformation for generating excel file which is to besent as email attachment.
Here I want to display the data from two internal tables in the same row in the excel. .I am using <tt:loop ref=".<table name>"> ... </tt:loop> for looping through the table. Can I loop two table simultaneously ? In that case how will I specify the fields in each table . Some of the fields in two tables are of same name and type.
Please help...
Thanks,
JissaHello Brian,
Thank you for your answer. It is approach I will use, I think. However let me ask: Would it be possible to have a Version in this layout, too? I mean to see, which value comes from Version A and which comes from Version B? Something like this:
Calendar Month Version Sales Amount
2011.01 B 200
2011.02 B 300
2011.03 A 260
2011.04 A 230
2011.05 A 200
A -
Radio group in classic report based on another column on the same row.
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
Application Express 4.1.0.00.32
How can I have a radio group column based on an LOV utilizing another column on the same row of the report?
For example: what if I had a survey application and depending on the likert scale that was assigned to the question there would be different possible answer choices:
Question 1 on row 1 of the report: The class instructor was friendly?
Likert scale choice is Agreement.
Choices on Radio Group: Strongly Agree, Agree, Undecided, Strongly Disagree
Question 2 on row 2 of the report: The class offered good materials?
Likert scale choice is Quality.
Choices on Radio Group: Excellent, Below Average, Average, Above Average, Excellent
The radio group can change per row depending on the Likert scale assigned to the question which is assigned to a different column on the row.
Can LOV utilize the column? :
SELECT scale_text
FROM scale_choices
WHERE scale_category_choice_id = 2 <<= this would be the Likert scale identifier
ORDER
BY display_orderHere is the answer:
APEX_ITEM.SELECT_LIST_FROM_QUERY(
p_idx IN NUMBER,
p_value IN VARCHAR2 DEFAULT NULL,
p_query IN VARCHAR2,
p_attributes IN VARCHAR2 DEFAULT NULL,
p_show_null IN VARCHAR2 DEFAULT 'YES',
p_null_value IN VARCHAR2 DEFAULT '%NULL%',
p_null_text IN VARCHAR2 DEFAULT '%',
p_item_id IN VARCHAR2 DEFAULT NULL,
p_item_label IN VARCHAR2 DEFAULT NULL,
p_show_extra IN VARCHAR2 DEFAULT 'YES')
RETURN VARCHAR2; -
How do I repeat the same row more than once in report 10g
How do I repeat the same row more than once in report 10g
So I can print the bar code more than once
in report;
Edited by: user11106555 on May 9, 2009 5:50 AMGREAT THAN X MAN
It is already working, but with the first ROW
select ename from emp
CONNECT BY ROWNUM<=5
ENAME
SMITH
SMITH
SMITH
SMITH
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
BUT I want this result
Item1
Item2
Item3
to
Item1
Item1
Item1
Item2
Item2
Item2
Item3
Item3
Item3 -
Data Sets - Is there a way to put two fields in the same row?
I am working on my first Spry Data Set (in Dreamweaver CS4) which, if I can get it figured out, will eventually be used as a calendar on a client's web site. You can see the beginning of the project here:
http://www.rieradesignco.com/calendarlist_spry.html
My question is, can I put two or more fields on one row? Specifically, I would like the part that looks like this...
3
[WED]
Fusion
... to look like this:
3 [WED] Fusion
I tried simply moving the fields (in Design View) so that they looked like they would be in the same row, but as you can see, that didn't do the trick. (You can see what I did here, in the highlighted part of the screenshot: http://www.rieradesignco.com/spryquestion.jpg). I also tried nesting a table within the table on my html data document that contained the three fields I needed - it worked okay, but that just makes the table more difficult to work with. I don't want to simply type the three items into one field, because it will be a long list and they all need to line up perfectly.
Is there another way to do it?Change the following line to include the red coloured parts
<div class="MasterColumn" spry:repeat="ds4" spry:setrow="ds4" spry:hover="MasterColumnHover" spry:select="MasterColumnSelected">
<span>{Dsp_#}</span><span>{Dsp_WkDay}</span><span>{Dsp_Event}</span>
</div>
The add the following style rule to your document:
.MasterColumn span {
display: inline-block;
I hope this helps.
Ben
Maybe you are looking for
-
Can we set key figure in between 2 char in open hub destination.
can any one tell me how can i insert a key description in between the char in open hub destinatio. Exp:my key description:quantity and char desc:material and plant. now i want field should be, Material. quantity plant when i am save the OHD ,i am get
-
Hi all, I was searching for Dreamweaver MX 2004 (i went for Dreamweaver MX 2004 because I am not a pro. designer and i didn't need Dreamweaver 8, was too expensive), but i could not find it. I am sure there are those who are out there looking like i
-
Handling Event of a custom component
Hi, I created a TwoStateButton from an AbstractButton. As long as it has two states, There's a repaint() occuring when the user clicks on it and it is written within the component. I want to also handle the click event from outside the component (act
-
Read Essbase cube with Java API
Hi,I would like to use the Java API to read an Essbase cube (incl. all Dimensions, Members, UDA, ...).Does anybody know where to find a useful example (a useful Java source code)?Thanks for your help Chris
-
Intro To Java Programming student needing help on how to download java SDK on 10.6.8
Hey Ladies and Gents, For the past hour I have been trying to download Java SDK for my 10.6.8 Mac. Can someone point me in the right direction. I am taking a course in intro to Java programming and the book I am using isnt as helpful as I hoped.