0

I have two columns IsHomeDelivery and Ispurchase whose values can be 0 and 1.

When value is 1 then i have to show text.

Means when ishomedelevery=1 then 'homedelivery ispurchase=1 then 'purchase'

i have formed following query:

SELECT
        LocationName,
        BranchName,
        AddLine1,
        AddLine2,
        Tel1,
        CASE
            WHEN LocationType='CC' THEN 'Call Center'
            WHEN LocationType='CL' THEN 'Operation'
        END AS 'Location Type',
        CASE
            WHEN IsPurchase= 1 THEN 'Purchase'
            WHEN IsHomeDelivery = 1 THEN 'Home Delivery'
            WHEN IsPurchase=1 AND IsHomeDelivery=1 THEN 'Purchase And Home Delevery'
        END AS 'Type'
    FROM PescaLocation

but unfortunatly its not working for both columns true.

Means when isHomedelivery and isPurchase both are 1 then it is showing 'purchase' whereas it should show 'home delivery and purchase'

plz help me.

4

1 回答 1

2

在第二种情况下,您缺少一个条件。当 IsPurchase 和 IsHomeDelivery 都为 1 时,“当 IsPurchase = 1”为真。

这是更新的代码。

select LocationName
    ,BranchName
    ,AddLine1
    ,AddLine2
    ,Tel1
    ,case 
        when LocationType = 'CC'
            then 'Call Center'
        when LocationType = 'CL'
            then 'Operation'
        end as 'Location Type'
    ,case 
        when IsPurchase = 1 and IsHomeDelivery = 0
            then 'Purchase'
        when IsPurchase = 0 and IsHomeDelivery = 1
            then 'Home Delivery'
        when IsPurchase = 1 and IsHomeDelivery = 1
            then 'Purchase And Home Delevery'
        end as 'Type'
from PescaLocation
于 2013-10-04T15:22:54.353 回答