-1

我有一个错误,我找不到此过程失败的原因。我只知道它做了一些我不知道的事情。有谁知道这是怎么回事?:|

ALTER PROCEDURE [dbo].[updateAccountPersonJob] 
    @department nvarchar(50),
    @description nvarchar(50),
    @personID int,
    @name nvarchar(50),
    @surname nvarchar(50),
    @email nvarchar(50),
    @username nvarchar(50),
    @password nvarchar(50),
    @status nvarchar(50)
AS
BEGIN TRANSACTION 
    DECLARE @missionID int, @jobID int;
    BEGIN TRY

       SET @jobID = (SELECT id FROM Jobs 
                     WHERE department = @department AND description = @description)

       UPDATE Persons 
       SET name = @name, surname = @surname, email = @email, jobID = @jobID 
       WHERE Persons.id = @personID

       UPDATE Accounts 
       SET Username = @username, Password = @password, Status = @status  
       WHERE Accounts.Password = @personID
    END TRY
    BEGIN CATCH
        SELECT 
            ERROR_NUMBER() AS ErrorNumber
            ,ERROR_SEVERITY() AS ErrorSeverity
            ,ERROR_STATE() AS ErrorState
            ,ERROR_PROCEDURE() AS ErrorProcedure
            ,ERROR_LINE() AS ErrorLine
            ,ERROR_MESSAGE() AS ErrorMessage;

        BEGIN IF @@TRANCOUNT > 0
            ROLLBACK TRANSACTION;
            PRINT('ROLLBACK')
        END
    END CATCH;

    IF @@TRANCOUNT > 0
        COMMIT TRANSACTION;

执行:

EXEC [dbo].updateAccountPersonJob
        @department = N'Facultatea de Matematica si Informatica',
        @description = N'Teacher',
        @personID = N'16',
        @name = N'Dummy',
        @surname = N'BarFOO',
        @email = N'bar@ba.com',
        @username = N'dummy',
        @password = N'd',
        @status = N'Teacher'

错误:

将 nvarchar 值“director”转换为数据类型 int 时转换失败。

4

1 回答 1

3

您正在对照nvarchar列检查personid(整数)列。password更新您的查询以使用正确的参数或列,您的代码应该可以工作

于 2013-06-03T20:24:41.817 回答