--更新用户评论统计
DECLARE @HasUserId INT
SELECT @HasUserId=UserId FROM [om_UserComments_Statistics] WHERE UserId=@UserId
IF(@HasUserId !=null)
BEGIN
INSERT INTO [om_UserComments_Statistics]
(
[UserId] ,
[AppId],
[SubjectID],
[IsActive] ,
[MostRecentPostDate] ,
[EnableAnonymousPosting] ,
[PostCount] ,
[ReplayCount] ,
[MostRecentPostCount] ,
[MostRecentReplayCount] ,
[PropertyNames] ,
[PropertyValues]
)
VALUES (@HasUserId,@AppId,@SubjectID,1,gedate(),1,1,0,0,0,'','')
END
ELSE
BEGIN
update [om_UserComments_Statistics] set PostCount=PostCount+1 where UserId=@HasUserId
END 怎么改正了? 谢谢。
DECLARE @HasUserId INT
SELECT @HasUserId=UserId FROM [om_UserComments_Statistics] WHERE UserId=@UserId
IF(@HasUserId !=null)
BEGIN
INSERT INTO [om_UserComments_Statistics]
(
[UserId] ,
[AppId],
[SubjectID],
[IsActive] ,
[MostRecentPostDate] ,
[EnableAnonymousPosting] ,
[PostCount] ,
[ReplayCount] ,
[MostRecentPostCount] ,
[MostRecentReplayCount] ,
[PropertyNames] ,
[PropertyValues]
)
VALUES (@HasUserId,@AppId,@SubjectID,1,gedate(),1,1,0,0,0,'','')
END
ELSE
BEGIN
update [om_UserComments_Statistics] set PostCount=PostCount+1 where UserId=@HasUserId
END 怎么改正了? 谢谢。
红色部分你那定义的?
是不是应该 @HasUserId not is null
if not exists (select 1 from dt where id=@id) insert
调试
@HasUserId is not null可以了 谢谢
贴出来留用ALTER PROCEDURE [dbo].[usp_Save_UserfComments]
(
@Id int,
@AppId int,
@SubjectId int,
@OwnerUserId int,
@UserId int,
@UserName varchar(50),
@ParentId int,
@IsApproved bit,
@TitleUrl varchar(256),
@body ntext,
@PostTime datetime,
@IsPrivate bit
)
AS
SET NOCOUNT ON
IF(@Id > 0)
BEGIN
--更改旧数据
UPDATE [om_UserComments]
SET
[AppId]= @AppId,
[SubjectId]= @SubjectId,
[OwnerUserId]= @OwnerUserId,
[UserId]= @UserId,
[UserName]= @UserName,
[ParentId]= @ParentId,
[IsApproved]= @IsApproved,
[TitleUrl]= @TitleUrl,
[body]= @body,
[PostTime]= @PostTime,
[IsPrivate]= @IsPrivate
WHERE Id=@Id
IF(@@ROWCOUNT > 0)
BEGIN
RETURN @Id
END
ELSE
BEGIN
RETURN -1
END
END
ELSE
BEGIN
--添加新记录
INSERT INTO [om_UserComments]
(
[AppId],
[SubjectId],
[OwnerUserId],
[UserId],
[UserName],
[ParentId],
[IsApproved],
[TitleUrl],
[body],
[PostTime],
[IsPrivate]
)
VALUES
(
@AppId,
@SubjectId,
@OwnerUserId,
@UserId,
@UserName,
@ParentId,
@IsApproved,
@TitleUrl,
@body,
@PostTime,
@IsPrivate
)
if(@ParentId=0 and @AppId=4)
update dbo.om_blog set CommentCount=CommentCount+1 where id=@SubjectId
else if(@ParentId=0 and @AppId=6)
update dbo.om_autobiography set [CommentCount]=CommentCount+1 where id=@SubjectId
else if(@ParentId=0 and @AppId=9)
update dbo.om_works set [CommentCount]=CommentCount+1 where id=@SubjectId
--更新用户评论统计
DECLARE @HasUserId INT
SELECT @HasUserId=UserId FROM [om_UserComments_Statistics] WHERE UserId=@UserId
IF(@HasUserId is not null)
BEGIN
update [om_UserComments_Statistics] set PostCount=PostCount+1 where UserId=@HasUserId
END
ELSE
BEGIN
INSERT INTO [om_UserComments_Statistics]
(
[UserId] ,
[IsActive] ,
[MostRecentPostDate] ,
[EnableAnonymousPosting] ,
[PostCount] ,
[ReplayCount] ,
[MostRecentPostCount] ,
[MostRecentReplayCount] ,
[PropertyNames] ,
[PropertyValues]
)
VALUES (@UserId,1,getdate(),1,1,0,0,0,'','')
END RETURN CONVERT(int,SCOPE_IDENTITY( ))
END
SET NOCOUNT OFF