服务器上有一个表,是配件的价格,我想当价格变化时能发现,如何把这个变化的东西导出为另一个表

解决方案 »

  1.   

    假如编号ID='A'的原价格为100 ,新进入库的价格为110,求出这两不同的情况吧?create procedure my_proc @id int,@price int
    as
    begin
      declare @bh as int
      if exists(select 1 from tb_old where id = @id and price = @price)
         set @bh = 0
      else 
         set @bh = 1
      insert into tb_new values(@id , @price , @bh)
    end
    go
    create table tb_old (id int , price int)
    insert into tb_old values(1 , 100)
    insert into tb_old values(2 , 200)
    create table tb_new (id int , price int , bh int) -- bh,有变话为1,无变化w为0
    go
    exec my_proc 1 , 100
    exec my_proc 2 , 100select * from tb_newdrop table tb_old,tb_new
    drop procedure my_proc/*
    id          price       bh
    ----------- ----------- -----------
    1           100         0
    2           100         1(2 行受影响)
    */
      

  2.   

    服务器上有一个表,是配件的价格,我想当价格变化时能发现,如何把这个变化的东西导出为另一个表
    -----------------------------------------
    当配件价格变化时,将变化的价格记录在另外一个表中?
    create table 配件价格表(name varchar(50),price money)
    insert into 配件价格表 select '主板',1050.00
    insert into 配件价格表 select 'CPU',250.00
    insert into 配件价格表 select '内存',350.00create table 配件价格变化表(name varchar(50),oldprice money,newprice money)create trigger tr_配件价格表 on 配件价格表 for update
    as
          insert into 配件价格变化表 select a.name,a.price,b.price from deleted a,inserted b
          where a.name=b.name
      

  3.   

    create   table   配件价格变化表(name   varchar(50),oldprice   money,newprice   money) create   trigger   tr_配件价格表   on   配件价格表   for   update 
    as 
                insert   into   配件价格变化表   select   a.name,a.price,b.price   from   deleted   a,inserted   b 
                where   a.name=b.name 
    这个是什么东西,能说明一下呀