Question

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.

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:

Now it has another problem:

The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Vasarlas__VevoID__47E69B3D". The conflict occurred in database "master", table "dbo.Vevo", column 'VevoID'.

the two tables look like this:

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

No correct solution

OTHER TIPS

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.

you have three varchar params, @Nev, @Cim and @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 ...

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.

if "Cluj-Napoca" is in the 'Your city' space, it means your problem is @Cim param. And u use it ın only one place, in else blog ; INSERT INTO Vevo VALUES (@maxId+1, @Nev, @Cim, 1)

check the Table Vevo, probably 3th column of that table (which u try to insert @Cim param) is INT not VARCHAR

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top