除列输出

时间:2015-12-23 19:34:08

标签: sql-server-2008

我可能会问这个问题完全错误,但在这里我们。 我正在创建一个存储过程来插入列的输出是否为3个值之一,然后对于每个工具都是如此。

列名是容器,3个值是罐,瓶,桶或False。

SELECT --DISTINCT
        ShiptoID = ID,  
        dba_Name = LEFT(MAX(Dba_Name), 35),
        LicName = LEFT(MAX(LicName), 35),
        Addr1 = MAX(Addr1),
        City = MAX(City),
        State = MAX(State),
        Zipcode = MAX(Zipcode),
        AreaCode = MAX(AreaCode),
                container....CASE 
            WHEN pl.container = Cans THEN 'TRUE'
            WHEN pl.Container = Bottles THEN 'TRUE'
            WHEN pl.container = Kegs THEN 'TRUE'
        ELSE  'FALSE'
        END,
                Lastupdate  

我在SELECT和WHERE子句中尝试过它,并且无法使语法正确。 有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分:0)

`Cans = pl.Container,         瓶子= pl.Container,         Kegs = pl.Container,         LastUpdate = GETDATE() - @ Today

FROM dbo.vw_RtlSalesNew rs with (nolock) 
INNER JOIN MM_Data.dbo.vw_VBS_Prodlist_UXT pl with (nolock) 
    ON pl.ProdUID = rs.ProdUID
WHERE rs.InvoiceDate >= '2015-12-01' --BETWEEN @StartDate AND @EndDate
    AND ro.CoTCode NOT IN(*..)  
    AND (SELECT *
        CASE 
        WHEN pl.container = 'Cans' THEN 'Cans'
        WHEN pl.Container = 'Bottles' THEN 'Bottles'
        WHEN pl.container = 'Kegs' THEN 'Kegs'
    ELSE  'FALSE'
    END )`

这个怎么样: