当我使用
执行以下动态存储过程时,我收到以下错误EXEC @return_value = [dbo].[proc_InsertEventDetails]
@EventID = 10254,
@EventDetType = 65,
@EventDetValue = 2,
@EventDetPriority = 0,
@CreatedBy = '4A47FE71-FC09-4E05-89E9-F68942BB9634'
消息8114,级别16,状态1,过程proc_InsertEventDetails,第0行 将数据类型varchar转换为bigint时出错。
我看了遍布stackoverflow的帮助很有用。谢谢
CREATE PROCEDURE [dbo].[proc_InsertEventDetails]
(
@EventID bigint
,@EventDetType int
,@EventDetValue int
,@EventDetPriority int
,@CreatedBy uniqueidentifier
)
AS
BEGIN
DECLARE @SQL NVARCHAR(MAX);
SET @SQL = 'IF NOT EXISTS(SELECT EventID FROM Events.[dbo].[EventDetail]
WHERE EventID = ' + CONVERT(VARCHAR(50), @EventID) + '
AND EventDetType = ' + CONVERT(VARCHAR(50), ISNULL(@EventDetType, 0)) + '
AND EventDetValue = ' + CONVERT(VARCHAR(50), ISNULL(@EventDetValue, 0)) + '
AND EventDetActive = 1)
BEGIN
INSERT INTO xxx.[dbo]..[EventDetail]
(
[EventID]
,[EventDetType]
,[EventDetValue]
,[EventDetPriority]
,[EventDetActive]
,[EventDetSort]
,[CreatedBy]
,[CreatedDateTime]
,[UpdatedBy]
,[UpdatedDateTime]
)
VALUES
(
' + CONVERT(VARCHAR(50), @EventID) + '
,' + CONVERT(VARCHAR(50), ISNULL(@EventDetType, 0)) + '
,' + CONVERT(VARCHAR(50), ISNULL(@EventDetValue, 0)) + '
,' + CONVERT(VARCHAR(50), ISNULL(@EventDetPriority, 0)) + '
,1
,0
,''' + CONVERT(NVARCHAR(500), ISNULL(@CreatedBy, NULL)) + '''
,''' + CONVERT(NVARCHAR(50), GETDATE()) + '''
,''' + NULL + '''
,''' + NULL + '''
)
END'
EXECUTE( @SQL )
END