3 回答

TA貢獻1834條經(jīng)驗 獲得超8個贊
我可能會誤會,但您有兩組數(shù)據(jù)要從一組中刪除數(shù)據(jù)庫中當前數(shù)據(jù)的字符串,然后在每次導入時都從一組中刪除字符串。
對于更新現(xiàn)有記錄,我只會使用SQL,那只需要發(fā)生一次。
但是,SQL并未針對這種操作進行優(yōu)化,因為您說的是編寫導入實用程序,所以我將在導入實用程序本身而不是在SQL中進行這些更新。這將是更好的性能選擇。您在用什么編寫實用程序?
另外,我可能會完全誤解該過程,因此,如果我偏離基準,我深表歉意。
編輯:
對于初始更新,如果您使用的是SQL Server 2005,則可以嘗試CLR函數(shù)。這是一個使用正則表達式的快速方法。不確定性能如何進行比較,我自己從未使用過此功能,除非現(xiàn)在進行快速測試。
using System;
using System.Data;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlString StripNonNumeric(SqlString input)
{
Regex regEx = new Regex(@"\D");
return regEx.Replace(input.Value, "");
}
};
部署之后,可以使用以下命令進行更新:
UPDATE table SET phoneNumber = dbo.StripNonNumeric(phoneNumber)

TA貢獻1810條經(jīng)驗 獲得超4個贊
我看到了帶有T-SQL代碼和PATINDEX的解決方案。我喜歡 :-)
CREATE Function [fnRemoveNonNumericCharacters](@strText VARCHAR(1000))
RETURNS VARCHAR(1000)
AS
BEGIN
WHILE PATINDEX('%[^0-9]%', @strText) > 0
BEGIN
SET @strText = STUFF(@strText, PATINDEX('%[^0-9]%', @strText), 1, '')
END
RETURN @strText
END

TA貢獻1906條經(jīng)驗 獲得超10個贊
replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(string,'a',''),'b',''),'c',''),'d',''),'e',''),'f',''),'g',''),'h',''),'i',''),'j',''),'k',''),'l',''),'m',''),'n',''),'o',''),'p',''),'q',''),'r',''),'s',''),'t',''),'u',''),'v',''),'w',''),'x',''),'y',''),'z',''),'A',''),'B',''),'C',''),'D',''),'E',''),'F',''),'G',''),'H',''),'I',''),'J',''),'K',''),'L',''),'M',''),'N',''),'O',''),'P',''),'Q',''),'R',''),'S',''),'T',''),'U',''),'V',''),'W',''),'X',''),'Y',''),'Z','')*1 AS string,
:)
- 3 回答
- 0 關注
- 579 瀏覽
添加回答
舉報