Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2011
    Posts
    78

    Unanswered: How to create a new column that's derived from an existing column?

    I want to create a new column called Cash that's derived from the COSTSPOT column. If the spot=0, then cash = 0, if cost=0, then cash=1
    But the column was renamed as Gross as well.

    How do I do that? I tried using the case function to do that, but don't know how to create a new column as Cash for that. Please help, thank you.


    select
    [I_DETAIL].[CASTMONTH]
    ,[I_DETAIL].[SLENGTH]
    ,Case [I_DETAIL].[COSTSPOT]as GROSS

    when [I_DETAIL].[COSTSPOT]=0 then [CASH]=0
    when [I_DETAIL].[COSTSPOT] >0 then [CASH]=1
    else 'Not Applicable'
    end as [COSTSPOT]



    FROM [Opti].[EDA4010].[I_DETAIL] as i_detail

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    Something like this?
    Code:
    select
    [I_DETAIL].[CASTMONTH]
    ,[I_DETAIL].[SLENGTH]
    ,Case 
    when [I_DETAIL].[COSTSPOT]=0 then '0'
    when [I_DETAIL].[COSTSPOT] >0 then '1'
    else 'Not Applicable'
    end as [CASH]
    
    FROM [Opti].[EDA4010].[I_DETAIL] as i_detail

  3. #3
    Join Date
    Jul 2011
    Posts
    78
    Thank you so much. It works =)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •