【发布时间】:2013-02-18 19:00:27
【问题描述】:
我目前正在使用 sql 游标来查找表以更新另一个表。我有一张包含很多短语的表格。如果这些短语中的任何一个落入更新表中的任何列,我想更新另一个表以设置 1。我正在使用 cursor 和 char 来查找短语。光标需要很长时间,我只是想知道是否可以使用其他任何东西来代替光标。谢谢。我正在使用 sql server,这是代码
declare @word varchar(max)
declare @aCursor cursor for
SELECT col from table
open acursor
fetch next from acursor into @word
while @@fetch_status=0
begin
SET @word = '' + @word + ''
UPDATE updatetable
SET updatecol = 'y'
FROM updatetable u, tableb b
WHERE u.id = b.id AND (CHARINDEX(@word, u.name) > 0 OR CHARINDEX(@word, u.city) >
fetch next from acursor into @word
end
close acursor
deallocate acursor
【问题讨论】:
-
SQL 只是 结构化查询语言 - 许多数据库系统使用的语言,但不是数据库产品...很多东西是高度特定于供应商的 - 所以我们真的需要知道您使用的是什么数据库系统(以及哪个版本)......
-
交叉应用也是一个选项:stackoverflow.com/questions/7492797/…
标签: sql sql-server cursor