1

我是这个领域的新手,我在执行这个过程时遇到问题,它给了我这个错误:“操作数类型冲突:浮点数与日期不兼容”

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
4

5 回答 5

3

检查你的INSERT陈述。您正在插入@check_datecheck_cash_checkno

于 2013-02-14T07:18:17.243 回答
1

有了修改后的错误,你的问题就很明显了。这些值与您的列不匹配。您正在插入@check_date该列check_cash_checkno

于 2013-02-14T07:17:29.850 回答
1

仅按列和变量名称,您提供参数的顺序似乎存在相当大的不匹配:

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)

例如@check_datecheck_cash_checkno@check_notes对齐,与 对齐check_status等。

我猜它应该重写为:

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)

这是 SQL 未能实现我们应该按名称而不是按序号位置引用列(属性)的关系理想的那些不幸的地方之一 - 您必须以VALUES匹配的顺序在子句中提供参数或值您为INSERT语句的列给出的顺序。

于 2013-02-14T07:18:56.757 回答
0

按照顺序插入值。

    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
    )

重现您的错误的简单示例:

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
于 2013-02-14T07:18:21.907 回答
0
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)

许多插入的值与选定的列顺序不匹配。

于 2013-02-14T07:23:20.417 回答