【问题标题】:SQL ERROR IS Operand type clash: int is incompatible with dateSQL 错误是操作数类型冲突:int 与日期不兼容
【发布时间】:2016-12-16 15:41:31
【问题描述】:
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');

但我收到一条错误消息:

消息 206,第 16 级,状态 2,第 13 行 操作数类型冲突:int 与日期不兼容

【问题讨论】:

  • 未引用 15-07-1990 是 15 减去 7 减去 1990,这是一个数字,而不是日期,请引用所有日期值。 (最好采用明确的格式,如 yyyy-mm-dd)

标签: sql sql-server


【解决方案1】:

将日期字段写入以下模式 {d 'yyyy-mm-dd'}

另一个指定:emp_id = 1 not 01,因为emp_id是int所以0丢失了。

试试这个:

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');

【讨论】:

    【解决方案2】:

    您应该在日期值周围加上引号。否则将被视为 算术表达式。

    因此,将您的 insert 查询更改为

    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'); 
    

    【讨论】:

      猜你喜欢
      • 2021-04-15
      • 1970-01-01
      • 1970-01-01
      • 2014-03-01
      • 2019-10-31
      • 2016-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多