日期:2014-05-17 浏览次数:20615 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-04-18 16:36:50
-- Version:
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64)
-- Jun 17 2011 00:54:03
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1, v.721)
--
----------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([单号] int,[行号] int,[商品] varchar(1),[数量] int)
insert [huang]
select 1,1,'a',5 union all
select 1,2,'b',5 union all
select 1,3,'C',5 union all
select 2,1,'a',5 union all
select 2,2,'b',5 union all
select 2,3,'C',5 union all
select 3,1,'a',5 union all
select 3,2,'b',5 union all
select 3,3,'C',5
--------------开始查询--------------------------
select CASE WHEN [单号] IN (2,3) THEN 1 ELSE [单号] END [单号],ROW_NUMBER()OVER (ORDER BY GETDATE()) [行号],[商品],[数量]
from [huang]
----------------结果----------------------------
/*