案例功能和通配符

时间:2017-08-01 12:24:24

标签: sql-server tsql

我希望为所有ZA系统添加一个通配符,以便将它们显示为“南非'系统。请参阅下面的代码。请协助充实它。

SELECT
      v_GS_COMPUTER_SYSTEM.Name0
     ,v_GS_PC_BIOS.SerialNumber0
     ,v_GS_COMPUTER_SYSTEM.Manufacturer0
     ,v_GS_COMPUTER_SYSTEM.Model0
     ,v_GS_OPERATING_SYSTEM.Caption0 AS [OS Type]
     ,v_GS_SYSTEM_CONSOLE_USAGE_MAXGROUP.TopConsoleUser0
     ,v_R_System.User_Name0 AS [Last Logged]
     ,v_GS_PC_BIOS.ReleaseDate0 AS [BIOS Date]
     ,v_GS_PC_BIOS.SMBIOSBIOSVersion0 AS [BIOS Version]
     ,v_GS_LOGICAL_DISK.FreeSpace0
     ,CASE v_GS_OPERATING_SYSTEM.BuildNumber0
           WHEN 9600 THEN 'Windows 8.1'
           ELSE v_GS_OPERATING_SYSTEM.BuildNumber0
      END AS B_NUM_0
     ,CASE v_GS_COMPUTER_SYSTEM.Name0
           WHEN CASE v_GS_COMPUTER_SYSTEM.Name0 LIKE 'ZA-%' THEN 'South Africa'
           ELSE v_GS_COMPUTER_SYSTEM.Name0 
      END AS CC
FROM
    v_GS_PC_BIOS
    INNER JOIN v_GS_COMPUTER_SYSTEM
        ON v_GS_PC_BIOS.ResourceID = v_GS_COMPUTER_SYSTEM.ResourceID
    INNER JOIN v_GS_OPERATING_SYSTEM
        ON v_GS_COMPUTER_SYSTEM.ResourceID = v_GS_OPERATING_SYSTEM.ResourceID
    INNER JOIN v_R_System
        ON v_GS_COMPUTER_SYSTEM.ResourceID = v_R_System.ResourceID
    LEFT OUTER JOIN v_GS_SYSTEM_CONSOLE_USAGE_MAXGROUP
        ON v_GS_COMPUTER_SYSTEM.ResourceID = v_GS_SYSTEM_CONSOLE_USAGE_MAXGROUP.ResourceID
    INNER JOIN v_GS_LOGICAL_DISK 
        ON v_R_System.ResourceID = v_GS_LOGICAL_DISK.ResourceID
WHERE
    (v_R_System.Operating_System_Name_and0 LIKE '%Workstation%')
    AND (v_GS_LOGICAL_DISK.FreeSpace0 IS NOT NULL)
ORDER BY
    [BIOS Date] ;

1 个答案:

答案 0 :(得分:1)

将CASE语句更改为此语法(CASE的语法):

CASE WHEN v_GS_COMPUTER_SYSTEM.Name0 LIKE 'ZA-%' THEN 'South Africa'
     ELSE v_GS_COMPUTER_SYSTEM.Name0 
    END AS CC