• ///xqm//2008.07.22 
    1,更新/添加仓存

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[up_tb_WD_uporadd]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[up_tb_WD_uporadd]
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_NULLS ON
    GO

    create   procedure  up_tb_WD_uporadd
    @warehouseID bigint,
    @productID bigint,
    @amount bigint
    as
    declare @quantity int
    declare @count int

    select @count=count(*) from tb_WarehouseDetails where productID=@productID and warehouseID=@warehouseID

    if(@count>0)
       begin
      
          select @quantity=quantity from  tb_WarehouseDetails where productID=@productID and warehouseID=@warehouseID

          select @quantity=@quantity+@amount

          update tb_WarehouseDetails set quantity=@quantity where productID=@productID and warehouseID=@warehouseID

       end
    else
       begin
          insert into tb_WarehouseDetails
          ([quantity],[productID],[warehouseID])
          values(@amount,@productID,@warehouseID)
       end
    go

  • 多使用存储过程吧!

    日期:2008-06-06 | 分类:技术┊CS | Tags:存储过程

       简要概述:

       简单点,Stored   Procedure是在服务端执行的已编译的SQL语句,运行效率和速度都要好,而从客户端编写的SQL还要提交到服务端才能执行,而存储过程最多只需提交几个参数,这是其一。  

      还有多态执行,就是一些功能相似的SQL如果都写在客户端,有时要写很多次,烦琐还容易出错,而存储过程只需在服务端写好调试好,根据客户端的变化情况...
  •     普通存储过程

             首先在查询分析器运行下面的代码来创建一个存储过程:

    create proc sp_singleresultset

    as

    set nocount on

    select * from customers 

     &nbs...
  • SQL Server 存储过程的分页

    日期:2007-10-05 | 分类:技术┊CS | Tags:存储过程

      来源:小张.NET
     
    建立表: 

    CREATE TABLE [TestTable] ( 
    [ID] [int] IDENTITY (11NOT NULL , 
    [FirstName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL , 
    [LastName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL , 
    [Country] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL , 
    [Note] [nvarchar] (2000) COLLATE Chinese_PRC_CI_AS NULL 
    ON [PRIMARY] 
    GO