可以考虑使用临时表来处理
假设数据来源表为B
1.先利用IDENTITY函数将B表的数据导入到一临时表
SELECT IDENTITY(int, 1,1) AS N_ID,* INTO #TmpData FROM B
2.读取A表中原流水号的最大值
DECLARE @MaxID AS INT
SELECT @MaxID =MAX(CAST(RIGHT([ID],8) As INT)) FROM A
3.将数据导入到目的表
--只演示序列号生成的方法
SELECT 'ziy' + CASE LEN(N_ID + @MaxID) WHEN 1 THEN '0000000' + CAST(@MaxID + N_ID AS VARCHAR(10))
WHEN 2 THEN '000000' + CAST(@MaxID + N_ID AS VARCHAR(10))
WHEN 3 THEN '00000' + CAST(@MaxID + N_ID AS VARCHAR(10))
WHEN 4 THEN '0000' + CAST(@MaxID + N_ID AS VARCHAR(10))
WHEN 5 THEN '000' + CAST(@MaxID + N_ID AS VARCHAR(10))
WHEN 6 THEN '00' + CAST(@MaxID + N_ID AS VARCHAR(10))
WHEN 7 THEN '0' + CAST(@MaxID + N_ID AS VARCHAR(10))
WHEN 8 THEN CAST(@MaxID + N_ID AS VARCHAR(10))
END AS N_ID
FROM #TmpData
----------------------------------------
这只是就2000版本必须使用临时表和IDENTITY函数,好象更高的版本就不必要这么麻烦
[[it] 本帖最后由 happynight 于 2008-5-6 08:41 编辑 [/it]]