我先创建了一个物料清单的U_CCC表,里面的物料(ItemName)的价格(Price)和OriPrice(原价格)要达到这样的一个效果,开始原价格为0。当Price修改第二次价格后就会把第一次的价格替换的原价格哪里,例如物料A 价格是100,修改好后价格变成200 那么原价格就得便是100
------解决方案--------------------
----------------------------------------------------------------
-- Author :fredrickhu(小F,向高手学习)
-- Date :2014-02-28 17:50:54
-- Verstion:
-- Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
-- Jul 9 2008 14:43:34
-- Copyright (c) 1988-2008 Microsoft Corporation
-- Enterprise Edition on Windows NT 6.1 <X86> (Build 7601: Service Pack 1)
--
----------------------------------------------------------------
--> 测试数据:[U_CCC]
if object_id('[U_CCC]') is not null drop table [U_CCC]
go
create table [U_CCC]([Price] int,[OriPrice] int)
insert [U_CCC]
select 100,0
--------------开始查询--------------------------
SELECT * INTO #tb FROM U_CCC
UPDATE U_CCC SET Price=200,OriPrice=a.Price FROM #tb AS a
SELECT * FROM U_CCC
DROP TABLE #tb
----------------结果----------------------------
/* Price OriPrice
----------- -----------
200 100
(1 行受影响)
*/