简体   繁体   English

SQL语句不起作用-“操作符类型冲突:float与日期不兼容”

[英]SQL statement not working - "Operand type clash: float is incompatible with date'

I'm a new to this field and i have a problem in executing this procedure it gives me this error: "Operand type clash: float is incompatible with date" 我是该领域的新手,我在执行此过程时遇到问题,它给了我这个错误:“操作数类型冲突:float与日期不兼容”

create proc store.checks_pro

(
@book_id int ,
@check_no int,
@check_date date ,
@check_status tinyint ,
@check_amount float,
@check_funder_name varchar (30),
@check_cash_type tinyint,
@check_cash_checkno varchar (20),
@check_notes varchar(100),
@check_userid int ,
@insertion_userid int ,
@insertiondate datetime 
)
as
begin
insert into  checks (book_id,check_amount,check_cash_checkno,check_cash_type,check_date,check_funder_name,check_no,check_notes,check_status,check_userid,insertion_userid,insertiondate)
values (@book_id,@check_no,@check_date,@check_status,@check_amount,@check_funder_name,@check_cash_type,@check_cash_checkno,@check_notes,@check_userid,@insertion_userid,@insertiondate)


end

Check your INSERT statement. 检查您的INSERT语句。 You are inserting @check_date into check_cash_checkno column. 您正在将@check_date插入check_cash_checkno列。

With the revised error, your problem is obvious. 使用修正的错误,您的问题很明显。 The values are not matching your columns. 这些值与您的列不匹配。 You are inserting @check_date in to the column check_cash_checkno . 要插入@check_date到列check_cash_checkno

Just going by column and variable names, there seems to be a considerable mismatch in the order you're supplying the parameters: 仅按列名和变量名来看,在提供参数的顺序中似乎存在很大的不匹配:

insert into  checks (
book_id,check_amount,check_cash_checkno,check_cash_type,check_date,check_funder_name,
check_no,check_notes,check_status,check_userid,insertion_userid,insertiondate)
values (
@book_id,@check_no,@check_date,@check_status,@check_amount,@check_funder_name,
@check_cash_type,@check_cash_checkno,@check_notes,@check_userid,@insertion_userid,@insertiondate)

Eg @check_date is aliging with the check_cash_checkno column, @check_notes aligns with check_status , etc. 例如, @check_date check_date符合check_cash_checkno列, @check_notescheck_status对齐,等等。

I would guess that it should be re-written as: 我猜应该将其重写为:

insert into  checks (
book_id,check_amount,check_cash_checkno,check_cash_type,check_date,check_funder_name,
check_no,check_notes,check_status,check_userid,insertion_userid,insertiondate)
values (
@book_id,@check_amount,@check_cash_checkno,@check_cash_type,@check_date,@check_funder_name,
@check_no,@check_notes,@check_status,@check_userid,@insertion_userid,@insertiondate)

This is one of those unfortunate places where SQL fails to live up to the relational ideal that we should reference columns (attributes) by name and not by ordinal position - you have to supply the parameters or values in the VALUES clause in an order that matches the order you gave for the columns of the INSERT statement. 这是SQL未能达到关系理想的不幸之处之一,我们应该按名称而不按顺序位置引用列(属性)-您必须以匹配的顺序在VALUES子句中提供参数或值您为INSERT语句的列指定的顺序。

Follow the order to insert value. 按照顺序插入值。

    insert into  checks
    (
    book_id,
    check_amount,
    check_cash_checkno,
    check_cash_type,
    check_date,
    check_funder_name,
    check_no,
    check_notes,
    check_status,
    check_userid,
    insertion_userid,
    insertiondate
    )
    values
    (
    @book_id,
    @check_amount,
    @check_cash_checkno,
    @check_cash_type,
    @check_date,
    @check_funder_name,
    @check_no,
    @check_notes,
    @check_status,
    @check_userid,
    @insertion_userid,
    @insertiondate
    )

Simple example to reproduce your error: 重现错误的简单示例:

create table test
(
sdate date,
roll nvarchar(50)
)
insert into test(sdate,roll) values(1,'2008-2-2') --false

insert into test(sdate,roll) values('2008-2-2',1) --true
INSERT INTO 
checks (book_id,check_amount,check_cash_checkno,check_cash_type,check_date,check_funder_name,check_no,check_notes,check_status,check_userid,insertion_userid,insertiondate)
VALUES    
(@book_id,@check_amount,@check_cash_checkno,@check_cash_type,@check_date,@check_funder_name,@check_no,@check_notes,@check_status,@check_userid,@insertion_userid,@insertiondate)

Many of the inserted values did not match the selected column order. 许多插入的值与选定的列顺序不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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