简体   繁体   English

SQL Server存储过程 - 转换错误

[英]SQL Server stored procedure - conversion error

I have a little problem with my stored procedure. 我的存储过程有点问题。 It's giving me this error: 它给了我这个错误:

Conversion failed when converting the varchar value 'Cluj-Napoca' to data type int. 将varchar值'Cluj-Napoca'转换为数据类型int时转换失败。

This is my code: 这是我的代码:

CREATE PROCEDURE UjVasarlas
@JID int,
@SZID int,
@Nev varchar(30),
@Cim varchar(30),
@Darab int,
@Datum varchar(30)
AS
SET NOCOUNT ON;
DECLARE @maxId int;
        SET @maxId = (SELECT MAX(VevoID) FROM Vevo);
iF EXISTS (SELECT * FROM Vevo WHERE Vevo.VevoNev = @Nev)
    begin
        INSERT INTO Vasarlas VALUES (@maxId+1, @JID, @SZID, @Darab, @Datum)
    end
    else
        INSERT INTO Vevo VALUES (@maxId+1, @Nev, @Cim, 1)
        INSERT INTO Vasarlas VALUES (@maxId+1, @JID, @SZID, @Darab, @Datum)

 GO     

 EXEC UjVasarlas 2, 2, 'Your Name', 'Your City', 2, '2013-01-22'

If it's helping I can tell you what it is for but I didn't wanted to waste time with that ... can anyone help? 如果有帮助我可以告诉你它的用途但是我不想浪费时间......有人可以帮忙吗? ... thx anticipated ;) ......期待;)

PS: PS:

Now it has another problem: 现在还有另一个问题:

The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Vasarlas__VevoID__47E69B3D". INSERT语句与FOREIGN KEY约束“FK__Vasarlas__VevoID__47E69B3D”冲突。 The conflict occurred in database "master", table "dbo.Vevo", column 'VevoID'. 冲突发生在数据库“master”,表“dbo.Vevo”,列'VevoID'中。

the two tables look like this: 这两个表看起来像这样:

  • Vasarlas ( VevoID, JatekID, SzallitoID, Darab, Datum ) VasarlasVevoID, JatekID, SzallitoID, Darab, Datum
  • Vevo ( VevoID, VevoNev, OrszagID, Cim ) VevoVevoID, VevoNev, OrszagID, Cim

My guess would be that your table schema does not match columns your insert, try specifying your columns explicitly 我的猜测是你的表架构与你的插入列不匹配,请尝试明确指定列

INSERT INTO Vasarlas(col1, col2, col3, col4, col5) 
VALUES (@maxId+1, @JID, @SZID, @Darab, @Datum)

The easiest way to get your list of columns is to drag and drop them from explorer in SQL Server Management Studio. 获取列列表的最简单方法是从SQL Server Management Studio中的资源管理器中拖放它们。

you have three varchar params, @Nev, @Cim and @Datum. 你有三个varchar参数,@ Nev,@ Cy和@Datum。

it seems you try to insert one of them to an integer column. 看来你试图将其中一个插入整数列。 check Vasarlas and Vevo tables or better trap begin end blocks to determine which insert statement causes the error ... 检查Vasarlas和Vevo表或更好的陷阱开始结束块以确定哪个插入语句导致错误...

by the way; 顺便说说; EXEC UjVasarlas 2, 2, 'Your Name', 'Your City', 2, '2013-01-22' can not return error for "Cluj-Napoca" string which is not included in params you sent. EXEC UjVasarlas 2,2,'Your Name','Your City',2,'2013-01-22'无法返回“Cluj-Napoca”字符串的错误,该字符串未包含在您发送的params中。

if "Cluj-Napoca" is in the 'Your city' space, it means your problem is @Cim param. 如果“Cluj-Napoca”在“你的城市”空间,那就意味着你的问题是@Cim param。 And u use it ın only one place, in else blog ; 而且你只在一个地方使用它,在其他博客中; INSERT INTO Vevo VALUES (@maxId+1, @Nev, @Cim, 1) 插入Vevo VALUES(@ maxId + 1,@ Nev,@ Cell,1)

check the Table Vevo , probably 3th column of that table (which u try to insert @Cim param) is INT not VARCHAR 检查表Vevo ,可能是该表的第3列(你试图插入@Cim param)是INT not VARCHAR

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

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