首页 > 技术文章 > 插入新列作为-序号列

szlixin 2015-04-09 14:14 原文

ROW_NUMBER() OVER(ORDER BY f.biaodanid desc) as KeyId

 

declare @yymm nvarchar(10)
set  @yymm  ='2015-04-08'
select f.biaodanid '订单号',d.dingdanshuliang  '订单数量',s.stock_id '物料号',name '物料名称', f.sumsl '发料量',ROUND(f.price,4)  '单价',
ROW_NUMBER() OVER(ORDER BY f.biaodanid desc) as KeyId
into BPM.dbo.erpA_rep_F3
from stock_sum s,dingdanfu f,dingdanzhu d    
where  s.stock_id = f.xuhao
and d.biaodanid = f.biaodanid
and CONVERT(char(10),cwdate,120)   = @yymm  order by stock_id,d.biaodanid

推荐阅读