0

所以我有一个表,可以说它是“tbl.items”,并且“tbl.items”中有一个“标题”列我想遍历每一行,对于“tbl.items”中的每个“标题”我想执行以下操作: 该列的数据类型为 nvarchar(max) 并包含一个字符串...

  1. 过滤字符串以删除诸如 in、out、where 等单词(停用词)
  2. 将字符串的其余部分与预定义的列表进行比较,如果匹配,则执行一些操作,包括在其他表中插入数据。

在编写 T-sql 脚本时,问题是我很无知,请帮助并指导我如何实现这一目标?是否可以通过编写sql脚本来实现??或者我必须用 c# 或任何其他语言开发控制台应用程序?

我正在使用 mssql 服务器 2008

提前致谢

4

1 回答 1

1

你想要一些东西。首先,查找 SQL Server 的函数语法,并编写如下内容:

-- Warning! Code written off the top of my head,
-- don't expect this to work w/copy-n-paste
create function removeStrings(@input nvarchar(4000))
as begin
    -- We're being kind of simple-minded and using strings
    -- instead of regular expressions, so we are assuming a
    -- a space before and after each word.  This makes this work better:
    @input = ' ' + @input

    -- Big list of replaces
    @input = replace(' in ','',@input)
    @input = replace(' out ','',@input)
    --- more replaces...
end

然后你需要一个表中的匹配列表,用“matchString”列调用这个“预定义”。

然后您可以使用以下命令检索匹配的行:

select p.matchString
  from items i
  join predefined p 
    on removeStrings(i.title) = p.matchString

一旦你有这些单独的部分工作,我提出一个新的问题,关于你可能用它们做什么特定的过程。

警告:不知道你有多少行或者你必须多久执行一次(每次用户保存一些东西?一次/天?),如果你明白我的意思,这不会完全是活泼的。因此,一旦您掌握了这些构建块,可能还会有一个后续问题,即如何以及何时去做。

于 2011-01-29T15:22:36.637 回答