我需要编写一个查询,它将为每个记录生成一种排序ID…例如:
ID Customer Name
-------------------------
C1000 customer #1
C1010 customer #2
C1020 customer #3
C1030 customer #4
现在,这些“C1000”ID不存在…只有客户的名字。我需要在选择时生成它们…所以我可以保存输出,然后导入到新系统中。
我怎样才能做到:
select
'C' + (some kinda code/math that generates the count based on a sequence? or row number?),
name
from Customers
=====================================
我最后做了以下操作(这样我可以配置启动和增量大小):
DECLARE @start int;
DECLARE @inc int;
set @start = 1000;
set @inc = 10;
Select 'C' + CAST(@start + (@inc * (ROW_NUMBER() OVER (ORDER BY name))) as varchar) as NewID, Name
from customer