3
我目前使用的是一個sql遊標來查找表來更新另一個表。我有一個包含很多短語的表格。我想更新另一個表來設置1,如果任何這些短語落入更新表中的任何一列。我使用遊標和字符來查找短語。光標需要很長時間,我只是想知道如果我可以使用其他任何東西而不是光標。謝謝。我使用的是SQL Server和這裏的代碼替代sql遊標
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
*** *** ***只是*結構化查詢語言* - 許多數據庫系統使用的語言,但不是數據庫產品......很多東西都是**高度**供應商特定的 - 所以我們真的需要知道你正在使用的數據庫系統**(和哪個版本)...... – 2013-02-18 19:31:09
交叉應用也是一個選項: http://stackoverflow.com/questions/7492797/using-cross -apply-在更新語句 – Limey 2013-02-18 19:41:54