I need to generate unique employee id like first letter of first name + first letter of last name + 1 in SQL using select statement.
For example:
If employee name is Rahul Khandekar, then Employee Id will be RK1.
If new employee joins with name Rakesh Kumar, then Employee Id will be RK2.
If new employee joins with name Krishna Pawar, then Employee Id will be KP1.
I'm using T-SQL syntax - but you could do something like this. I'm assuming it's always 2 characters and then your number (however long)
SELECT 'RK' + CONVERT(varchar(10),ISNULL(MAX(SUBSTRING(EmployeeID,3,10)),0)+1)
FROM Employees
WHERE EmployeeID LIKE 'RK%'
I have a requirement where I am adding new column from a select query like this:
select
sy.FIRST_NAME || sy.LAST_NAME as full_name,
e.*
from
employee e
left join
USERS sy on sy.SY_USER_ID = act.SY_USER_ID;
I have all the columns of the employee table in my entity class as fields - except for full_name.
How to map this full_name column to a field in my entity class?
I believe you have columns first_name and last_name as you use to create full_name column. Therefore, you already mapped the full_name column to align with all previous columns in the table. Try run your SQL.
I am new to the Oracle APEX AB and currently trying to implement a specific mask that we need for work:
We have a table in our SQL-Database for employees. It looks like the following:
| staff_id | name | salary | department_id|
The goal is to have an own input mask, where I have to write down the staff_id, e.g. 100600.
Then I click a submit button and the output is created dynamically in the same mask as a text that consists the following (column value in brackets):
"Employee [name] has a salary of [salary] € and works in department [department_id].
This scenario is visualized in the following picture:
My problem now is that I don't understand the following things:
Which element do I need to use in the page designer as an input?
(Currently I am trying it with a numberfield)
How can I extract the value out of this numberfield and use it into
an sql query for the output text.
Third: How can I create a hard coded textfield that will only appear
after submitting with columns that dynamically adjust to the
Input-ID?
So the workflow should be something like:
First: Insert staff_id into numb_field and submit
Second: SELECT name, salary, department_id FROM EMPLOYEE WHERE STAFF_ID = numb_field_value
Third: Put the received values name, salary, department_id in a hardcoded text as the gap fillers and give it as an output on the screen.
Thank you for your help! :)
Visualization of the Input and Output of the procedure
Here's how:
create Number datatype item, let's call it P72_STAFF_ID
create a button; let it Submit the page
create a display only item with no label (so that it is "invisible")
create a process which runs PL/SQL code:
select 'Employee ' || name || ' has a salary of ' || salary ||
' € and works in department ' || department_id
into :P72_INFO
from employees
where staff_id = :P72_STAFF_ID;
Run the page, enter employee's ID and hit the button. You'll see something like this:
The below is a simplified version of the problem I am facing
Let's say I have an employee and a department table in Hive. My goal is to load the data from these 2 tables into a 3rd one below. However, the 3rd table has a few dummy columns set to null and will not be filled by data from either of the employee or department tables. Is it possible to still load the employee and department data and just set the other fields to null?
Employee table(id,first_name,last_name,age,department_id,salary)
1,John,Smith,23,1,40000
2,Bob,Wilson,25,1,45000
3,Fred,Krug,37,2,75000
4,Jeremy,Fisher,41,3,110000
Department table(id,name)
1,Sales
2,IT
3,Marketing
End result(dummy_column0,employeeID,first_name,last_name,age,salary,department_name,dummy_column1)
null,1,John,Smith,23,40000,Sales,null
null,2,Bob,Wilson,25,45000,Sales,null
null,3,Fred,Krug,37,75000,IT,null
null,4,Jeremy,Fisher,41,110000,Marketing,null
Question is given the schema of the end result, how do I load the rest of the non-null data into the 3rd table? Any help would be much appreciated! The end results table already exists at this point so I cannot just recreate it from scratch
Yes. Hive doesn't care of the column names. Its just position of the columns that matter the most. you just have to structure your query in a way so dummy columns have nulls.
insert overwrite table tablename
select null, employeeID, first_name,last_name, age, salary, dept.deptName, null
from employee e join dept d on e.dept_id = d.dept_id;
I want to execute a SQL sentence, there are two tables
Table Name Description
********* *********
H_person Employee Data
Modelorg Position Data
I want to write an sql that shows "who is connected to whom". In h_person table
Fıeld Name Description
********* *********
p_no Employee ID
P_ad Employee Name
P_soyad Employee Surname
P_pzsyn Employee Position ID
In Modelorg Table
Fıeld Name Description
********* *********
Pozkod Position ID
Pozad Position Name
USTPOZKOD the upper position (POZKOD connected to USTPOZKOD)
USTPOZKOD is also the POZKOD at the same time,there is a hierarchial connection.
I would like to form a report shows person ID, Name, Surname, Position Name, Upper Position Name, Manager ID and Maneger Name-Surname(helding Upper Position ID).
Additionally sometimes Upperpostion may be empty and when executing the report, it will be null. I would like to add a rule, If upperposition is null, bring 2 level upper manager
In H_person Table
First Data
*** ***
P_no=14556 P_ad=John
p_Soyad= Onel
P_Pzsyn= 72878 /Account Specialist
Second Data
P_no=14656
P_ad=Sara
p_Soyad= Yildiz
P_Pzsyn= 5455 /Account Manager
*** ***
In Modelorg Table
Pozkod=72878
Pozad=Account Specialist
Ustpozkod=5455 (Account Manager) USTPOZKOD is at the same time a pozkod.
select p_no, p_ad, p_soyad, Pozad, USTPOZKOD (we connected pozkod to USTPOZKOD and I woul like to bring "who held this USTPOZKOD(NAME, Surname) from h_person, modelorg.
USTPOZKOD also equals to POZKOD because someone helds this position
You need to use a common table expression (CTE) to build the recursive query.
An example:
WITH #rec AS
(
SELECT ID, ParentID
FROM RecTable
WHERE ParentID = 0
UNION ALL
SELECT R.ID, R.ParentID
FROM RecTable R
INNER JOIN #rec P ON R.ParentID = P.ID
)
SELECT *
FROM #rec