有条件地将值放入列中

Putting value in column conditionally

我正在尝试在 SQL 服务器中创建一个视图,如下所示:

CREATE VIEW HeaquartersSales 
AS
    SELECT
        gs.district,
        gs.MonthToDateSales,
    FROM 
        GlobalSales AS gs
GO 

但是,如果地区名称中有 "G0-",我只想将销售数字放在 MonthToDateSales 中。

我该怎么做?

您似乎在寻找 CASE 表达式:

CREATE VIEW HeaquartersSales AS
SELECT
  district,
  CASE WHEN district like '%G0-% THEN MonthToDateSales END as MonthToDateSales
FROM GlobalSales AS gs
GO