更新游标中的行 [英] update rows in cursor

查看:109
本文介绍了更新游标中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新游标中设置的值,在while循环中,下面是我的sql查询,在语句

  update中给出错误 filteredCommunities 
set SearchStaticCount



plz help我想只更新游标值

以下是查询

 声明  @ loopCounter   int  
set @ loopCounter = 0
声明 @社区 as varchar 30
声明 @ Counter as int

声明 filteredCommunities CURSOR FOR
选择 SearchStaticCount,关键字来自 SearchStatic ss inner join UnitListing us on ss.Keyword = us.UnitListingName where ServiceTypeId = ' 卖' CategoryTypeId = < span class =code-string>' Commercial'
for < span class =code-keyword>更新 SearchStaticCount
OPEN filteredCommunities
FETCH NEXT FROM filteredCommunities INTO @ Counter @ Community
WHILE (@ loopCounter< 10)
BEGIN
update filteredCommunities
set SearchStaticCount = @ loopCounter
FETCH NEXT FROM filteredCommunities INTO @ Counter @社区
END
CLOSE filteredCommunities
DEALLOCATE filteredCommunities

解决方案

请阅读我的问题。



声明

更新 TableName SET FieldName = FieldValue



将更新所有数据(对于整个表格)。



更新单个记录:

  UPDATE  TableName  SET  FieldName = FieldValue  WHERE  UniqueField = UniqueValue 


I want to update the values set in the cursor, inside a while loop, below is my sql query that give error in the statement "

update filteredCommunities
                set SearchStaticCount


"plz help i want to update only cursor values
following is the query

declare @loopCounter int
set @loopCounter=0
Declare @Community as varchar(30)
Declare @Counter as int

Declare filteredCommunities CURSOR FOR 
select SearchStaticCount,Keyword from SearchStatic ss inner join UnitListing us on ss.Keyword=us.UnitListingName  where ServiceTypeId='Sell' and CategoryTypeId='Commercial' 
for update of SearchStaticCount
OPEN filteredCommunities
    FETCH NEXT FROM filteredCommunities INTO @Counter,@Community
	        WHILE(@loopCounter<10)
        BEGIN
		        update filteredCommunities
				set SearchStaticCount=@loopCounter           
 				FETCH NEXT FROM filteredCommunities INTO @Counter,@Community
        END
CLOSE filteredCommunities
DEALLOCATE filteredCommunities

解决方案

Please, read my caomment to the question.

The statement

UPDATE TableName SET FieldName = FieldValue


will update all data (for entire table).

To update single record:

UPDATE TableName SET FieldName = FieldValue WHERE UniqueField=UniqueValue


这篇关于更新游标中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆