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