更新所有其他记录

时间:2010-04-12 08:50:19

标签: sql sql-server

我在下面有一个查询。我想添加一个条件,如果@IsPrestigeFeatured = 0的参数然后更新所有其他行<> IsprestigeFeatured列中的PropertyId为0,如果@IsPrestigeFeatured = 1则为IsprestigeFeatured = 1 where propertyId = PropertyId

我查看了case语句/ if语句,但我似乎无法正确使用语法。 欢呼声

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)

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

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)