Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 更新所有其他记录_Sql_Sql Server - Fatal编程技术网

Sql 更新所有其他记录

Sql 更新所有其他记录,sql,sql-server,Sql,Sql Server,下面我有一个问题。我想添加一个条件,如果参数@ispretigefeatured=0,则将ispretigefeatured列中的所有其他行PropertyId更新为0,如果@ispretigefeatured=1则ispretigefeatured=1,其中PropertyId=PropertyId 我已经研究了case语句/if语句,但是我似乎没有正确的语法。 干杯 如果使用TSQL,请签出如果使用TSQL,请签出更改过程dbo.Update\u属性 @propertyId int、@pro

下面我有一个问题。我想添加一个条件,如果参数
@ispretigefeatured=0
,则将ispretigefeatured列中的所有其他行
PropertyId
更新为0,如果
@ispretigefeatured=1
ispretigefeatured=1,其中PropertyId=PropertyId

我已经研究了case语句/if语句,但是我似乎没有正确的语法。 干杯


如果使用TSQL,请签出

如果使用TSQL,请签出

更改过程dbo.Update\u属性
@propertyId int、@propertyTypeId int、@Name ntext、@Price int、,
@DescriptionResultsExcerpt文本,@Description-ntext,
@特性ntext、@IsRenovation int、@IsCharacter int、,
@IsPrestige int,@ishomepageint,
@ISPRESTIGEINT、@CityId int、,
@部门ID int,@communiteid int
作为
更新
财产
设置IsPrestigeFeatured=@IsPrestigeFeatured
哪里
(@IsPrestigeFeatured=0和PropertyId@PropertyId)或
(@ispretigefeatured=1和PropertyId=@PropertyId)
更改过程dbo.Update\u属性
@propertyId int、@propertyTypeId int、@Name ntext、@Price int、,
@DescriptionResultsExcerpt文本,@Description-ntext,
@特性ntext、@IsRenovation int、@IsCharacter int、,
@IsPrestige int,@ishomepageint,
@ISPRESTIGEINT、@CityId int、,
@部门ID int,@communiteid int
作为
更新
财产
设置IsPrestigeFeatured=@IsPrestigeFeatured
哪里
(@IsPrestigeFeatured=0和PropertyId@PropertyId)或
(@ispretigefeatured=1和PropertyId=@PropertyId)

您使用的是什么数据库/语言?MS SQL、mySQL、Oracle?您使用的是什么数据库/语言?微软SQL,mySQL,Oracle?基本上只能有一个Prestige Featured属性,因此,如果用户在我的编辑ui中选中了该复选框,那么我想为propertyid=propertyid的行设置列isprestigefeatured=1,对于我想设置isprestigefeatured=0的所有其他行,基本上只能有一个Prestige Featured属性,因此如果用户在我的编辑界面中选中了该复选框,然后我想为propertyid=propertyid的那一行设置列ispretigefeatured=1,并为我想设置ispretigefeatured=0的所有其他行设置列ispretigefeatured=0可以根据上面的sql查询给我一个完整的示例吗,因为我刚刚用上面的示例愚蠢地删除了所有测试数据,所以请检查我的更新。备份测试数据并运行过程。如果isprestigefeatured=0,我不想将值更新到所有集合列中。如果ispretigefeatured=0,我只想将“0”更新到ispretigefeatured的列中,如果propertyid propertyid。如何将更新仅限于该列。嗨,Veer。谢谢你的帮助。老实说,我还是有点困惑。请阅读我在asp.net论坛上发布的帖子。。。链接就在那里。我也不明白上面的意思是什么!我已经看过你的文章了,接下来将研究如何“用begin事务和commit语句包装update语句”。我真的不明白你哪里有两个更新语句。你试过我的密码了吗?如果它不起作用,你能详细说明你的需要吗?你能给我一个基于我上面sql查询的完整例子吗,因为我刚刚愚蠢地用上面的例子删除了我所有的测试数据检查我的更新。备份测试数据并运行过程。如果isprestigefeatured=0,我不想将值更新到所有集合列中。如果ispretigefeatured=0,我只想将“0”更新到ispretigefeatured的列中,如果propertyid propertyid。如何将更新仅限于该列。嗨,Veer。谢谢你的帮助。老实说,我还是有点困惑。请阅读我在asp.net论坛上发布的帖子。。。链接就在那里。我也不明白上面的意思是什么!我已经看过你的文章了,接下来将研究如何“用begin事务和commit语句包装update语句”。我真的不明白你哪里有两个更新语句。你试过我的密码了吗?如果它不起作用,你能详细说明你的需要吗?
ALTER PROCEDURE dbo.Update_Property
@propertyId int,
@propertyTypeId int,
@Name ntext,
@Price int,
@DescriptionResultsExcerpt text,
@Description ntext,
@Characteristics ntext,
@IsRenovation int,
@IsCharacter int,
@IsPrestige int,
@IsHomepageFeatured int,
@IsPrestigeFeatured int,
@CityId int,
@DepartmentId int,
@CommuneId int

As
UPDATE     Property
SET        Name = @Name, PropertyTypeID = @propertyTypeId, Price = @Price, 
            DescriptionResultsExcerpt = @DescriptionResultsExcerpt, 
            Description = @Description, Characteristics = @Characteristics, 
            IsRenovation = @IsRenovation, IsCharacter = @IsCharacter, 
            IsPrestige = @IsPrestige, IsHomepageFeatured = @IsHomepageFeatured, 
            IsPrestigeFeatured = @IsPrestigeFeatured, CityId = @CityId, 
            DepartmentId = @DepartmentId, CommuneId = @CommuneId

FROM Property 
WHERE (PropertyId = @PropertyId)
ALTER PROCEDURE dbo.Update_Property     
    @propertyId int, @propertyTypeId int, @Name ntext, @Price int,
    @DescriptionResultsExcerpt text, @Description ntext, 
    @Characteristics ntext, @IsRenovation int, @IsCharacter int, 
    @IsPrestige int, @IsHomepageFeatured int,
    @IsPrestigeFeatured int, @CityId int, 
    @DepartmentId int, @CommuneId int    
As 

UPDATE 
    Property 
SET         IsPrestigeFeatured = @IsPrestigeFeatured
WHERE 
    (@IsPrestigeFeatured = 0 AND PropertyId <> @PropertyId) OR
    (@IsPrestigeFeatured = 1 AND PropertyId = @PropertyId)