create proc stud_use
@no char(10),
@nam nvarchar(4),
@birth datetime,
@sex nchar(1),
@add nvarchar(20),
@tel char(12),
@zip char(10),
@1 decimal(3,0),
@code int output
as
begin 
if(@code=1)
begin
     select @nam=NAME,@birth=BIRTHDAY,@sex=GENDER,@add=ADDRESS,@tel=TELCODE,@zip=ZIPCODE,@1=MARK from stud_info where STUD_ID=@no
end
else
if(@code=2)
begin
     insert into stud_info values(@no,@nam,@birth,@sex,@add,@tel,@zip,@1)
end
else
if(@code=3)
begin
     update stud_info
     set  name=@nam,
          birthday=@birth,
          gender=@sex,
          address=@add,
          telcode=@tel,
          zipcode=@zip,
          MARK=@1
     where stud_id=@no
end
else
if(@code=4)
begin
     delete from stud_info where stud_id=@no
end
else
begin
 print'请输入正确的操作类型!'
end
end
go
我想要实现增加 删除 修改 检索功能  但是我这样写是不对的 希望谁指点下 谢谢

解决方案 »

  1.   

    --你没有返回code,不需要定义输出参数.
    create proc stud_use 
    @no char(10), 
    @nam nvarchar(4), 
    @birth datetime, 
    @sex nchar(1), 
    @add nvarchar(20), 
    @tel char(12), 
    @zip char(10), 
    @1 decimal(3,0)
    as 
    begin 
      if @code not between 1 and 4 
         print'请输入正确的操作类型!' 
      else
      begin
      if (@code=1) 
         select @nam=NAME,@birth=BIRTHDAY,@sex=GENDER,@add=ADDRESS,@tel=TELCODE,@zip=ZIPCODE,@1=MARK from stud_info where STUD_ID=@no 
      if (@code=2) 
         insert into stud_info values(@no,@nam,@birth,@sex,@add,@tel,@zip,@1) 
      if (@code=3) 
         update stud_info 
         set  name=@nam, 
              birthday=@birth, 
              gender=@sex, 
              address=@add, 
              telcode=@tel, 
              zipcode=@zip, 
              MARK=@1 
         where stud_id=@no 
      if (@code=4) 
         delete from stud_info where stud_id=@no 
      end
    end 
    go或者.create proc stud_use 
    @no char(10), 
    @nam nvarchar(4), 
    @birth datetime, 
    @sex nchar(1), 
    @add nvarchar(20), 
    @tel char(12), 
    @zip char(10), 
    @1 decimal(3,0)
    as 
    begin 
      if @code not between 1 and 4 
         print'请输入正确的操作类型!' 
      else
      begin
        if (@code=1) 
           select @nam=NAME,@birth=BIRTHDAY,@sex=GENDER,@add=ADDRESS,@tel=TELCODE,@zip=ZIPCODE,@1=MARK from stud_info where STUD_ID=@no 
        else
        begin
          if (@code=2) 
             insert into stud_info values(@no,@nam,@birth,@sex,@add,@tel,@zip,@1) 
          else
          begin
          if (@code=3) 
             update stud_info 
             set  name=@nam, 
                  birthday=@birth, 
                  gender=@sex, 
                  address=@add, 
                  telcode=@tel, 
                  zipcode=@zip, 
                  MARK=@1 
             where stud_id=@no 
          else
            if (@code=4) 
               delete from stud_info where stud_id=@no 
          end
        end
      end
    end 
    go 
      

  2.   

    但是还是执行删除操作的时候需要所有字段的值啊  而不是仅仅需要stud_id的值 还是说必须要输入所有信息
      

  3.   

    删除时需要
     where 条件(字段的值)
      

  4.   

    create proc stud_use 
    @no char(10), 
    @nam nvarchar(4), 
    @birth datetime=null, 
    @sex nchar(1)=null, 
    @add nvarchar(20)=null, 
    @tel char(12)=null, 
    @zip char(10)=null, 
    @1 decimal(3,0)=null即可 解决要额外参数的问题 不过还是不够完美 谢谢