简体   繁体   中英

SQL ERROR IS Operand type clash: int is incompatible with date

CREATE TABLE prime_emp (
emp_id INT not null,
first_name VARCHAR(14) not null,
 last_name VARCHAR(14) not null,
 birth_date DATE not null,
 father_name VARCHAR (14) not null,
 mather_name VARCHAR (14),
joing_date DATE not null,
departmen VARCHAR(14) not null,
Primary key (emp_id)
)
select * from prime_emp
insert into prime_emp
(emp_id,first_name,last_name,birth_date,father_name,mather_name, joing_date,departmen)
values(01,'Ashish','Soni',15-07-1990,'Suman','Usha',28-10-2013,'Media');

But I got an error message:

Msg 206, Level 16, State 2, Line 13 Operand type clash: int is incompatible with date

Write date field as following pattern {d 'yyyy-mm-dd'}

Another appoint: emp_id = 1 not 01, because emp_id is int so 0 has lost.

Try this:

insert into prime_emp
(emp_id,first_name,last_name,birth_date,father_name,mather_name, joing_date, departmen)
values
(1,'Ashish','Soni',{d '1990-07-15'},'Suman','Usha',{d '2013-10-28'},'Media');

You should give quotes around date values . Other wise it will be treated as an arithmetic expression.

So change your insert query to

insert into prime_emp
(emp_id,first_name,last_name,birth_date,father_name,mather_name, joing_date,departmen)
values(01,'Ashish','Soni','15-07-1990','Suman','Usha','28-10-2013','Media'); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM