首先感谢您的光临和帮助!
整天我一直在想办法使这种迁移概念尽可能快。基本上我有很多这样的行:
WO-ID|Line Number|Note Tran Number|Note
1 |1 |1 |... 50 char
1 |1 |2 |... 30 char
1 |1 |3 |5 char
在所有这些操作的结尾,我需要将它们放在一起,在它们之间插入回车符,然后将它们分解成60个字符的文本,即:
WO-ID|Line Number|Note Tran Number|Note
1 |1 |1 |...50 char from line 1 and 10 char from line 2
1 |1 |2 |...20 char from tran 2 and 5 char from tran 3
现在,我确实有多种工作方式,但是我正在努力寻找最快的方法来实现这一目标。将字符串连接在一起并添加回车符既快捷又容易,但是拆分字符串的过程将花费很长时间,因为字符串最终被拆分成更多的“事务”。现在,具有107K条记录的数据集上所有注释的总长度为4,244,809个字符。
所有记录(包括300个字符)为3,829,351。这将在大约50秒内完成。其余的415,458需要一分钟零45秒。
这是我正在使用的查询(如果有更好的方法,我想听听,那么我想不出比“页面”更好的方法了!显然,有一个插入多个值的更快方法,但我对此不太满意):
Declare @SplitSize int;
declare @numbersTable table (number int);
insert into @numbersTable values(1);
insert into @numbersTable values(2);
insert into @numbersTable values(3);
insert into @numbersTable values(4);
insert into @numbersTable values(5);
insert into @numbersTable values(6);
insert into @numbersTable values(7);
insert into @numbersTable values(8);
insert into @numbersTable values(9);
insert into @numbersTable values(10);
insert into @numbersTable values(11);
insert into @numbersTable values(12);
insert into @numbersTable values(13);
insert into @numbersTable values(14);
insert into @numbersTable values(15);
insert into @numbersTable values(16);
insert into @numbersTable values(17);
insert into @numbersTable values(18);
insert into @numbersTable values(19);
insert into @numbersTable values(20);
insert into @numbersTable values(21);
insert into @numbersTable values(22);
insert into @numbersTable values(23);
insert into @numbersTable values(24);
insert into @numbersTable values(25);
insert into @numbersTable values(26);
insert into @numbersTable values(27);
Set @SplitSize = 60;
Select Main.wo_note_fac, main.wo_note_ro_num, main.wo_note_line_num,
n.Number,SubString(main.note, @SplitSize*(n.Number -1) + 1, @SplitSize)
From (
SELECT DISTINCT note2.wo_note_fac, note2.wo_note_ro_num, note2.wo_note_line_num,
(
SELECT rtrim(note1.wo_note) + char(10) AS [text()]
FROM dbo.wonotes note1
WHERE note1.wo_note_fac = note2.wo_note_fac and note1.wo_note_ro_num = note2.wo_note_ro_num and note1.wo_note_line_num != 0 and note2.wo_note_line_num = note1.wo_note_line_num
ORDER BY note1.A4GLIdentity
FOR XML PATH ('') ,TYPE).value('.','NVARCHAR(MAX)') --need this .value thing to make sure xml characters aren't escaped
[note]
FROM dbo.wonotes note2
)main
Inner Join @numbersTable n On @SplitSize*n.Number < Len(main.note) + @SplitSize
我们的客户在该表中拥有1000万条以上的记录,我希望他们不要在2.5小时或更长时间内停机!