首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

update case field 有关问题

2012-01-19 
update case field 问题UPDATE[Organization]SETCASE@CourseTypeIDWHEN0THEN[ConcurrentUserLicenses][Co

update case field 问题
UPDATE  
      [Organization]  
SET
        CASE   @CourseTypeID   WHEN   0   THEN   [ConcurrentUserLicenses]   =[ConcurrentUserLicenses]   -   1
ELSE   InstructorLedCourseLicenses=InstructorLedCourseLicenses   -1
WHERE
        [OrganizationID]   =   @OrganizationID

我想实现的功能是这样的  
中的SET   语句怎么写呢?   谢谢

[解决办法]
try

UPDATE
[Organization]
SET
ConcurrentUserLicenses = (Case When @CourseTypeID = 0 Then ConcurrentUserLicenses - 1 End),
InstructorLedCourseLicenses = (Case When @CourseTypeID != 0 Then InstructorLedCourseLicenses - 1 End)
WHERE
[OrganizationID] = @OrganizationID
[解决办法]
UPDATE [Organization]
SET [ConcurrentUserLicenses]=CASE @CourseTypeID WHEN 0 THEN [ConcurrentUserLicenses] - 1
ELSE InstructorLedCourseLicenses -1 end
WHERE [OrganizationID] = @OrganizationID
语法的问题
[解决办法]
UPDATE [Organization]
SET ConcurrentUserLicenses=CASE WHEN @CourseTypeID=0 THEN ConcurrentUserLicenses - 1
else ConcurrentUserLicenses end,
SET InstructorLedCourseLicenses=CASE WHEN @CourseTypeID=0 THEN InstructorLedCourseLicenses - 1
else InstructorLedCourseLicenses end
WHERE [OrganizationID] = @OrganizationID

热点排行