我不是一个真正的SQL人,所以我很挣扎。下面的"program"
有什么问题阻止我创建这个存储过程?任何帮助或清理建议都会很棒。
ALTER PROCEDURE [dbo].[CreateHaystackExportJob_Program]
-- Add the parameters for the stored procedure here
@ID AS VARCHAR
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @JobCount AS INT
SELECT
@JobCount = COUNT (*)
FROM
dbo.HaystackExportJobs
WHERE
ID = @ID AND ExportType = "program"
IF @JobCount = 0
INSERT INTO dbo.HaystackExportJobs (ID,ExportType) VALUES (@ID,"program")
END
答案 0 :(得分:5)
首先,您应该在@id
参数上包含一个长度。
其次,SQL Server中的字符串值应使用单引号,因此请删除双引号并将其替换为"program"
周围的单引号。所以你的代码将类似于:
CREATE PROCEDURE [dbo].[CreateHaystackExportJob_Program]
-- Add the parameters for the stored procedure here
@ID AS VARCHAR(50) -- place a length on this parameter or an int if this is numeric
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @JobCount AS INT
SELECT
@JobCount = COUNT (*)
FROM
dbo.HaystackExportJobs
WHERE
ID = @ID
AND ExportType = 'program'
IF @JobCount = 0
INSERT INTO dbo.HaystackExportJobs (ID,ExportType)
VALUES (@ID,'program')
END
答案 1 :(得分:3)
奇怪的事情:
答案 2 :(得分:0)
使用单引号,而不是双引号。以下是使用双引号的示例。 ExportType =“program”