我要读一个表中的内内容并让其中一个字段加1
如Select * from Table1 where Id=@IdUpdate Table1 Set Counter = Counter + 1用一条存储过程怎么写?请用最优性能的方法,谢谢。

解决方案 »

  1.   

    CREATE PROCEDURE sp_Test
        @Id INT
    AS
    Update Table1 Set Counter = Counter + 1
    where Id=@Id
      

  2.   

    Update Table1 Set Counter = Counter + 1 Where Id=@Id还是:
    create procedure test
         @Id nvarchar 
    asbeginSelect * from Table1 where Id=@IdUpdate Table1 Set Counter = Counter + 1

    end
      

  3.   

    Update Table1 Set Counter = Counter + 1 where Id=@IdSelect * from Table1 where Id=@Id
      

  4.   

    刚找到:
    BEGIN 和 END 语句用于将多个 Transact-SQL 语句组合为一个逻辑块。任何时候当控制流语句必须执行一个包含两条或两条以上 Transact-SQL 语句的语句块时,请使用 BEGIN 和 END 语句。skytear() ( ) 信誉:97 正解谢了,结帖。
      

  5.   

    出错了:( 我想要读出表中某一个Id=@Id各个字段的值,并使这一行的Counter加1,就是一个阅读计数器的效果,
    这个的话居然使所有表的所有行的Counter都加1
    create procedure test
         @Id nvarchar 
    asbeginSelect * from Table1 where Id=@IdUpdate Table1 Set Counter = Counter + 1

    end
      

  6.   

    哈哈 可以了
    在这里
    Update Table1 Set Counter = Counter + 1
    也加上Where Id=@id谢谢各位
    写网站就这么有意思 :)