Sql Server存储过程从一个表中抓取数据填充到另一张表中

 

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

-- =============================================
-- Author:  <alex,,Name>
-- Create date: <2011-9-20,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[ToCrmIvNumProd]
(
  @ItemOneNo varchar(30)
)
AS
BEGIN  
    declare @prodNo varchar(30)
    declare @ivnum numeric(17,8)
    select @prodNo=itemno,@ivnum=qty from uv_validstock where itemno=@ItemOneNo
    if exists(select itemno from crm_iv_middle_tb where itemno=@ItemOneNo)
      begin
          if @prodNo !=''
          begin
          update crm_iv_middle_tb set itemno=@prodNo,ivnum=@ivnum where itemno=@ItemOneNo
          end   
      end
    else
      begin
        if @prodNo != ''
        begin
        insert into crm_iv_middle_tb(itemno,ivnum) values(@prodNo,@ivnum)
        end
      end    
END

 

展开阅读全文

没有更多推荐了,返回首页