好的,这个问题涉及一个复杂的存储过程的一部分,它将新实体插入到几个表中。
我目前遇到困难的部分需要这样工作:
例如:#www.test& aol.com - > #wwwtest& aol.com,#www.test& aolcom
这是一个艰难的开始,我知道部分内容不起作用,但我认为这是一个不错的起点:
declare @test varchar(50)
set @test = '#www.test&aol.com'
declare @len int, @ctr int
set @len = LEN(@test)
set @ctr = 1
declare @newName varchar(50)
declare @matchedChar table(match varchar(10),replaceChar varchar(10),processed int default(0))
declare @alternateEntities table(name varchar(50))
declare @repChar varchar(10)
declare @selectedChar varchar(1)
while @ctr<=@len
begin
--Insert matching characters and replacement characters into table variable,
--this is necessary for the # character, which has multiple replacement characters
insert into @matchedChar (match,replaceChar) select Character,ReplacementCharacter from tblTransliterations where Character = SUBSTRING(@test,@ctr,1)
--loop
while (select COUNT(*) from @matchedChar where processed = 0)>0
begin
--get the top character from table variable
set @selectedChar = (select top 1 match from @matchedChar where processed = 0)
--get replacement character
set @repChar = (select top 1 replaceChar from @matchedChar where processed = 0)
--replace character in name string
--set @newName = (select Replace(@test,@selectedChar,@repChar))
set @newName = (select STUFF(@test,CHARINDEX(@selectedChar,@test),1,@repChar))
--update table variable to move onto next character
update @matchedChar set processed = 1 where @repChar = replaceChar
--add name with replaced character to alternate entities table
insert into @alternateEntities (name) values (@newName)
end
set @ctr = @ctr+1
set @len = LEN(@test)
end
select * from @alternateEntities
答案 0 :(得分:0)
使用基于集合的方法,而不是循环。
创建临时表并填充NVARCHAR(100)类型的“单词”列,调用临时表Invalid_Words
为每个令牌在Invalid_Words上创建一个列,并使col type = bit
您现在已经定义了每个单词匹配的标记。
下一部分是替换。