无法在INSERT中使用WHERE

时间:2015-01-10 11:29:36

标签: sql-server

USE [Training]
GO

IF EXISTS ( SELECT 1 FROM dbo.sysobjects where NAME = 'USP_insertNotesToGoal_RPTS' )
      DROP PROCEDURE [dbo].[USP_insertNotesToGoal_RPTS] 

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[USP_insertNotesToGoal_RPTS] 
      @GoalNotes varchar(500),
      @UserName varchar(50),
      @GoalName varchar(50)
AS
BEGIN
  /*
  Author: Shivang Rana
  Description: To add notes to a goal
  Date:10-01-2015
  Version History:1.0
  Date      Purpose
  */
  declare @UserID int

  select UserID 
  from User_details 
  where UserName = @UserName

  insert into Goal_Details (GoalNotes) 
  values (@GoalNotes) 
  where GoalName = @GoalName and UserID = @UserID

  PRINT 'USP_insertNotesToGoal_RPTS'
END
GO

2 个答案:

答案 0 :(得分:2)

您可能需要更新语句,而不是INSERT

尝试用此

替换插件
UPDATE Goal_Details SET
    GoalNotes = @GoalNotes
WHERE GoalName = @GoalName and UserID = @UserID

答案 1 :(得分:1)

您应该使用更新而不是插入。

您需要更新

   update table_name 
   set column_name=@parameter 
   where column_name=@parameter2