我的程序有问题,我的代码中没有发现错误。我认为这是因为 StopProc。任何人都可以检查我的存储过程以查看它是否有效?
ALTER PROCEDURE dbo.Update_FeatureUsers
(
@FeatureID int,
@UserID nvarchar (MAX),
@CreatedUserID int
)
AS
SET NOCOUNT ON
Declare @ParmDefinition nvarchar (400)
Declare @Query nvarchar(MAX)
SET @Query = N''
SET @Query = @Query + N'DELETE FeatureUsers '
SET @Query = @Query + N'FROM FeatureUsers '
SET @Query = @Query + N'WHERE FeatureUsers.FeatureID = @FeatureID '
SET @Query = @Query + N' AND FeatureUsers.UserID NOT IN ('+ @UserID +')'
EXECUTE sp_executesql @Query
SET @Query = N''
SET @Query = @Query + N'INSERT INTO FeatureUsers (FeatureID, UserID, CreatedUserID) '
SET @Query = @Query + N'SELECT @FeatureID, Usager.UserID, @CreatedUserID '
SET @Query = @Query + N'FROM Usager WITH (NOLOCK) '
SET @Query = @Query + N'WHERE Usager.UserID IN ('+ @UserID +') '
SET @Query = @Query + N' AND Usager.UserID NOT IN '
SET @Query = @Query + N' ( '
SET @Query = @Query + N' SELECT FeatureUsers.UserID '
SET @Query = @Query + N' FROM FeatureUsers WITH (NOLOCK) '
SET @Query = @Query + N' WHERE FeatureUsers.UserID IN ('+ @UserID +') '
SET @Query = @Query + N' AND FeatureUsers.FeatureID = @FeatureID '
SET @Query = @Query + N' ) '
SET @ParmDefinition = N'@FeatureID int '
EXECUTE sp_executesql @Query, @ParmDefinition, @FeatureID = @FeatureID
SET NOCOUNT OFF
RETURN