How to generate absent report of all employee between two specific date in laravel? - laravel-4

You have only attendance table with id, name, date.
EmployeeId int primary key
EmployeeName nvarchar(50)
Date

Related

How to copy another columns value to a new created value in SNOWFLAKE

I am trying to add values to a newly created column from another column in SNOWFLAKE database, could someone please help.
I want values of OrderID column to be inserted in CompanyID
The table has to be updated:
UPDATE tab
SET CompanyID = OrderID
-- WHERE CompanyID IS NULL;
If the table is createad first time column CompanyID could be added inside CTAS:
CREATE TABLE tab
AS
SELECT OrderID AS CompanyID, OrderID, CustomerName
FROM db_soure_name.schema_name_table_name;

Unable to insert date data into oracle table

Unable to insert date data into oracle table. Please find the below query and error
Query:
INSERT INTO TEST.SUPPLIER
(SUPPLIER_ID, SUPPLIER_NAME, CONTACT_NAME, DOB)
VALUES(6, 'rr', 'ss','2019-06-19');
Error:
SQL Error [1843] [22008]: ORA-01843: not a valid month
VALUES(6, 'rr', 'ss','2019-06-19'), Error Msg = ORA-01843: not a valid month
ORA-01843: not a valid month
Please try the below query:
INSERT INTO TEST.SUPPLIER (SUPPLIER_ID, SUPPLIER_NAME, CONTACT_NAME, DOB) VALUES(6, 'rr', 'ss',DATE '2019-06-19');**
DATE keyword interprets the following string as a date.
I am sure you would have used DOB as date when defining the table.
You may directly enter date in DD/MON/YYYY format, with MON as first three letters of month.
To format date to YYYY-MM-DD format, you may use DATE before the string which will look like DATE '2019-07-20'
Here's a quick run through for all the points
create table supplier(SUPPLIER_ID number, SUPPLIER_NAME varchar2(20), CONTACT_NAME varchar2(20), DOB date);
insert into supplier values(12, 'supplier1', 'contact1', '18/JAN/2019');
insert into supplier values(13, 'supplier2', 'contact2', date '2019-07-20');
select * from supplier;
SUPPLIER_ID SUPPLIER_NAME CONTACT_NAME DOB
----------- -------------------- -------------------- ---------
12 supplier1 contact1 18-JAN-19
13 supplier2 contact2 20-JUL-19
Hope it sorts!
You need to covert your date string to DATE type. Before inserting the value
INSERT INTO TEST.SUPPLIER (SUPPLIER_ID, SUPPLIER_NAME, CONTACT_NAME, DOB)
VALUES(6, 'rr', 'ss',TO_DATE('2003/05/03', 'yyyy/mm/dd'))

how to create a foreign key in Oracle

How to link the MgrId in ManagerProject to EmpId in the Employee table ?
This is wat I tried :
CREATE TABLE Employee(EmpId varchar2(5),
EmpName varchar2(25),
DeptId varchar2(3),
Salary Number(8),
Constraint PK_addn primary key (EmpId, DeptId),
Constraint fk_Department foreign key (DeptId) references Department (DeptId));
But the second table failed to be created :
CREATE TABLE ManagerProject(ProjId varchar2(4),
MgrId varchar2(5),
StartDate Date,
EndDate Date,
Constraint fk_managerproject foreign key (MgrId) references Employee (EmpId),
Constraint PK_Managerproject Primary key(ProjId, MgrId, StartDate));
It displays
ORA-02270: no matching unique or primary key for this column-list
The error message says that you are trying to create a FK referencing a column on which there is no Unique or Primary Key constraint.
Assuming that you don't want to add the column DeptId to ManagerProject, you need to add a unique key on employee:
alter table Employee add constraint empId_UK unique ( empId)
But this strongly depends on what your schema should be.
If you want to add the column DeptId to ManagerProject, you will need to edit your FK to both use EmpId and DeptId in referencing employee.

populate dropdown for country,state,city in codeigniter using single table only

i am working on a codeigniter project where i need to populate dropdown for country,state and city but using only one table i.e., all country, state and city data should be in one table .How to do this ?
You can use the following table structure
CREATE TABLE places
(
id int NOT NULL,
country_id int DEFAULT '0',
state_id int DEFAULT '0',
name varchar(255)
);
All countries will have a default country_id and state_id of 0. The country_id for the states will be the id of a country and a state_id of 0. All cities will have a country_id and a state_id.

Update query resulting wrongly

I have table called company_emp. In that table I have 6 columns related to employees:
empid
ename
dob
doj, ...
I have another table called bday. In that I have only 2 columns; empid and dob.
I have this query:
select empid, dob
from company_emp
where dob like '01/05/2011'
It shows some list of employees.
In the same way I have queried with table bday it listed some employees.
Now I want to update the company_emp table for employees who have date '01/05/2011'.
I have tried a query like this:
update company_name a
set dob = (select dob from bday b
where b.empid=a.empid
and to_char(a.dob,'dd/mm/yyyy') = '01/05/2011'}
Then all the records in that row becoming null. How can I fix this query?
You're updating every row in the company_name/emp table.
You can fix that with a correlated subquery to make sure the row exists, or more efficiently by placing a primary or unique key on bday.empid and querying:
update (
select c.dob to_dob,
d.dob from_dob
from company_emp c join dob d on (c.empid = d.empid)
where d.dob = date '2011-05-01')
set to_dob = from_dob
Syntax not tested.

Resources