0
我試圖從.net插入存儲過程中的ID值,ID的int值在存儲過程中插入負值。將負值傳遞到存儲過程
但是,當一個負值傳遞給它一個錯誤'*'附近的錯誤語法。
請幫幫我。
這是當我執行的代碼如下,我得到的錯誤我的存儲過程
ALTER PROCEDURE [dbo].[HotlinePlusAdministration_ArticleMigrator]
@Id AS INT,
[email protected] AS INT,
[email protected] AS Varchar(200),
[email protected] AS datetime,
@DestLinkServer AS VARCHAR(50),
@UserID AS VARCHAR(8),
@ReturnMsg AS VARCHAR(1000) OUTPUT
AS
BEGIN
DECLARE @Query AS NVARCHAR(4000)
DECLARE @Log AS VARCHAR(8000)
DECLARE @ArticleID as int
DECLARE @NewArticleID as int
DECLARE @ArticleKeyExists as int
DECLARE @Title as varchar(200)
DECLARE @CategoryID as INT
DECLARE @ArticleDate as varchar(30)
DECLARE @ParmDefinition nvarchar(500);
SET XACT_ABORT ON -- Required for nested transaction
BEGIN TRAN
-- Check if ArticleID exists in Destination Server
SET @Query = N' SELECT @ArticleKeyExists = COUNT(*)
FROM ' + @DestLinkServer + '.HL2_61.dbo.Article' + ' where ArticleKey = ' + str(@Id)
SET @ParmDefinition = N' @ID int, @ArticleKeyExists int OUTPUT';
EXECUTE sp_executesql @Query , @ParmDefinition, @ID, @ArticleKeyExists OUTPUT;
--EXECUTE sp_executesql 1234,'BRHLSQL8','BRWSQLDC',@return = retnmsg
IF @@ERROR <> 0
BEGIN
ROLLBACK TRANSACTION
SET @ReturnMsg = @Log + '<span style="color:red;">ERROR: <br></span>'
RETURN -1
END
--Delete existing Articles for select page
set @Query = 'DELETE FROM ' + @DestLinkServer +
'.HL2_61.dbo.Article ' +
'WHERE ArticleKey = ' + CONVERT(VARCHAR, @Id)
--'WHERE CategoryID = ' + CONVERT(VARCHAR, @CategoryID) + ' and Title = ''' + @Title + ''' and ArticleDate = ''' + @ArticleDate + ''''
Print @Query
EXEC(@Query)
。
DECLARE @return_value int,
@ReturnMsg varchar(1000)
EXEC @return_value = [dbo].[Migrator]
@Id = -1591276581,
@DestLinkServer = N'SQLDC',
@UserID = N'10c1',
@ReturnMsg = @ReturnMsg OUTPUT
SELECT @ReturnMsg as N'@ReturnMsg'
SELECT 'Return Value' = @return_value
GO
請人幫助我..
感謝
這是一個很長的代碼片段。嘗試減少它到3線repro。我想,那樣你會自己發現錯誤。 – usr 2012-01-31 20:21:17
我厭倦了在零件中執行Sprocedure,並發現當我在@Id中傳遞負值時,我得到了該錯誤。但事情是我不知道該怎麼做才能通過負值沒有錯誤。 – user1005479 2012-01-31 20:25:27