For some reason, I need only one query to finish my project.
select empId, lastName,firstName,employee.sinNum,departmentId,position,baseSalary,gender,age,emailAddr,phoneNum from employee join person
on employee.sinNum = person.sinNum
Above will generate a result set and I want to insert values into this result set.
Insert into (empId, lastName,firstName,employee.sinNum,departmentId,position,baseSalary,gender,age,emailAddr,phoneNum from
employee join person on employee.sinNum = person.sinNum) values
('meng','xue',333,10,'clerk',3000,'male',30,'j@tt.com',2321)
But it does not work. So how to combine the "insert into (select...)"? Appreciate it for your time. : )
Updated (Here are tables I created)
create table person (
sinNum int primary key not null,
gender varchar(6) not null check (gender in ('male','female')) default
'female',age int not null check (age>=18 and age<=100),
emailAddr varchar (50) not null,
phoneNum int not null,
)
create table employee (
empId int identity (1,1) unique,
lastName varchar (30) not null,
firstName varchar (30) not null,
sinNum int not null unique foreign key references person (sinNum),
departmentId int not null foreign key references department (departmentId),
position varchar (20) not null check (position in
('clerk','assistant','supervisor','manager','director','president')) default
'clerk',
baseSalary float not null
)
One person should have employee info and personal info. The two table connect each other by sinNum
When a new employee join the company. We need all register all his(her) info. This is why I want join two table as one result and using one statement to add all info.