output parameter i sp
Vi har en tabel der ser sådan ud:CREATE TABLE [dbo].[tblBugs] (
[BugID] [int] IDENTITY (1, 1) NOT NULL ,
[BugTypeID] [int] NOT NULL ,
[BugDescription] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[BugDescReply] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[BugStatusID] [int] NOT NULL ,
[BugReportDate] [smalldatetime] NOT NULL,
[BugFixedDate] [smalldatetime] NULL,
[BugHandlerID] [int] NULL ,
[ProjectID] [int] NOT NULL,
[CustomerID] [int] NOT NULL,
[BugAttachmentCount] [int] NOT NULL
)
En SP der ser sådan ud:
CREATE PROCEDURE addBug (@buggID int out,@BugTypeID integer, @BugDescription text, @BugDescReply text, @BugStatusID integer, @BugReportDate smalldatetime, @BugFixedDate smalldatetime, @BughandlerID integer, @ProjectID integer, @CustomerID integer, @BugAttachmentCount integer)
AS
INSERT INTO tblBugs (BugTypeID, BugDescription, BugDescReply, BugStatusID, BugReportDate, BugFixedDate, BughandlerID, ProjectID, CustomerID, BugAttachmentCount)VALUES(@BugTypeID, @BugDescription, @BugDescReply, @BugStatusID, @BugReportDate, @BugFixedDate, @BughandlerID, @ProjectID, @CustomerID, @BugAttachmentCount)
SELECT @buggID= [BugID] FROM [dbo].[tblBugs] WHERE [BugID] = SCOPE_IDENTITY()
GO
Og når jeg skriver dette:
exec addBug '1', 'test24242', 'null', '1', '1999-01-01 22:59:59.997', null, '1', '1', '1',' 0'
Siger SQL det her:
Server: Msg 8114, Level 16, State 4, Procedure addBug, Line 0
Error converting data type varchar to int.
Hvad er det jeg ikke fatter? Jeg vil gerne have det BugID nummer tilbage som blev oprettet med denne bug.