【发布时间】:2016-06-10 15:45:24
【问题描述】:
我正在尝试将字符串传递给存储过程。我的代码是:
CREATE PROCEDURE AddCondition
@CondName varchar(50),
@CondDesc varchar(50)
AS
DECLARE @CondID int
--This code gets the next ID for the table
SET @CondID = (SELECT MAX([Condition ID]) FROM [dbo].[Tube Conditions]) + 1
SET @CondID = ISNULL(@CondID,1)
--This code adds records to the table
INSERT INTO [dbo].[Tube Conditions] ([Condition ID],[Condition Name],[Description])
VALUES (@CondID, @CondName, @CondDesc)
GO
我尝试执行:
DECLARE @aName varchar(50), @aDesc varchar(50)
SET @aName = 'Lathed'
SET @aDesc = 'The tube has been lathed to size'
EXECUTE AddCondition @aName, @aDesc
GO
但我不断收到错误:
消息 245,级别 16,状态 1,过程 AddCondition,第 51 行
将 varchar 值“车床”转换为数据类型 int 时转换失败。
在处理 int 和 float 值时,同样的过程也有效,所以我不确定我在这里缺少什么。我正在使用带有 SQL Server Express 的 SQL Server 2014 Management Studio。
提前致谢!
【问题讨论】:
-
(1) 您的错误消息在第 51 行显示错误,您的 5 行代码中没有第 51 行。 (2) 你可以使用一个标识列而不是那个获取下一个 id 的东西
标签: sql sql-server tsql stored-procedures