什么意思? 没太看明白.小问题弄得好复杂. 要修改SUB就修改SUB,要修改其它就修改其它.Create Project UP_1
@id int,
@Subject nvarchar(2000),
@succ bool output=false
...
if(exits(select id from VoteSubject ))
begin
update ...
set @output=true;
end2 CREATE PROCEDURE UP_VoteSubject_Update
@id int,
@VEID int,
@Order int,
@SubjectType char(1),
@IsShow bit

解决方案 »

  1.   

    /*----------------------------------------*/
    /*--Author:xiaojie.shi--*/
    /*--CreateTime:07-4-6--*/
    CREATE PROCEDURE UP_VoteSubject_Update
    @id int,
    @VEID int,
    @Subject nvarchar(200),
    @Order int,
    @SubjectType char(1),
    @IsShow bit
     AS 
    declare @r int,@r1 int;
    select @r = count(subject) from VoteSubject where Subject = @Subject  and [order] = @Order and SubjectType = @SubjectType and isshow = @IsShow
    if @r = '1' 
    return '2'; 
     --print '您未作任何修改该';

    select @r1 = count(subject) from VoteSubject where [id] not in (select([id]) from votesubject where subject= @subject) and subject = @Subject 
    if @r1 = '1'
    return '3';
    --print '您修改该的标题已经存在';
    else if @r1 = '0' 
    UPDATE VoteSubject SET 
    [VEID] = @VEID,[Subject] = @Subject,[Order] = @Order,[SubjectType] = @SubjectType,[IsShow] = @IsShow
    WHERE [id] = @id
                 return '1';
    --print'修该成功'
    GO
    我自己解决
      

  2.   

    CREATE   PROCEDURE   UP_VoteSubject_Update 
    @id   int, 
    @VEID   int, 
    @Subject   nvarchar(200), 
    @Order   int, 
    @SubjectType   char(1), 
    @IsShow   bit 
    AS
    --标题已经存在且不是自己
    IF EXISTS(SELECT * FROM VoteSubject WHERE Subject=@Subject AND [id]<>@id)
    RETURN 3
    ELSE
    BEGIN
    IF EXISTS (SELECT * FROM VoteSubject WHERE [id]=@id AND [VEID]=@VEID AND Subject=@Subject AND [order]=@Order AND SubjectType=@SubjectType AND isshow=@IsShow)
    --未作任何修改,其实没必要。
    RETURN 2
    ELSE
    UPDATE VoteSubject SET [VEID]=@VEID,[Subject]=@Subject,[Order]=@Order,[SubjectType]=@SubjectType,[IsShow]=@IsShow 
    WHERE [id]=@id
    END
    --修该成功
    RETURN 1
      

  3.   

    不能重复,将subject字段设为主键,就可以解决了。。麻烦