简体   繁体   English

如何在SQL Server 2000上使用正确的订单号将添加的记录更正到表中?

[英]How to correct added records to the table with correct order number on SQL Server 2000?

How to correct added records to the table with correct order number on SQL Server 2000? 如何在SQL Server 2000上使用正确的订单号将添加的记录更正到表中?

I have the following ordered table: 我有以下排序表:

OrderNo Data
      0    A
      1    B
      2    C

I need to add the following records to the table (with order saving): 我需要将以下记录添加到表中(保存订单):

OrderNo Data
      2    E
      3    F
      1    D

And to get the following as the result on the table: 并获得以下结果作为表格结果:

OrderNo Data
      0    A
      1    B
      2    C
      3    D
      4    E
      5    F

How to do this on SQL Server 2000? 如何在SQL Server 2000上执行此操作?

PS OrderNo can't be identity or unique. PS OrderNo不能是身份或唯一的。

Simulating ROW_NUMBER in SQL Server 2000 在SQL Server 2000中模拟ROW_NUMBER

select (select count(*) 
        from Table1 as e2
        where e2.OrderNo <= e1.OrderNo) as OrderNo, e1.Data
from Table1 as e1
ORDER BY OrderNo

Assuming your table name is orders... 假设您的表名是orders ...

SELECT count(order_count.OrderNo), orders.Data
FROM orders
  LEFT OUTER JOIN orders order_count
    ON order_count.Data < orders.Data
GROUP BY orders.Data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM