Field gets changed to Money type

Answered Field gets changed to Money type

  • Monday, March 18, 2013 7:42 PM
     
     

    Field is defaulted to UA=F but in SQL the field is changing to money.

    How can I make this field a varchar field?  The below is what I have but not working

    , Field = case when dedcode<>'ABC' then cast(NULL as varchar(9))

    when dedcode = 'ABC' then

    case when cast(Salary as varchar) >= '120000' then '120000'

    when cast(Salary as varchar) between '20000' and '120,000' then CEILING(Salary/1000)*1000 --

    when cast(Salary as varchar) <= '20000' then '20000' end --

    end

    Outcome is always 120000.00 not what the statement states.

All Replies

  • Monday, March 18, 2013 8:07 PM
    Moderator
     
     Proposed Answer Has Code

    Try:

    , Field = case when dedcode<>'ABC' then cast(NULL as varchar(9))
    
    when dedcode = 'ABC' then
    
    case when Salary >= 120000 then '120000'
    
    when Salary between 20000 and 120000 
    
    
    then CONVERT(VARCHAR(9),CEILING(Salary/1000)*1000) -- the problem is here
    
    when Salary <= 20000 then '20000' end 
    
    end

    Also, no need to convert salary to varchar for comparison.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    • Proposed As Answer by Jesús López Monday, March 18, 2013 8:09 PM
    •  
  • Monday, March 18, 2013 8:08 PM
     
     

    ... THEN CONVERT(varchar(100), CEILING(Salary/1000) * 1000)


    Too late :-(
  • Monday, March 18, 2013 8:20 PM
     
     

    Still coming up as money XXXXX.XX

    Not making it a flat number with no .00.

  • Monday, March 18, 2013 8:29 PM
    Moderator
     
     Answered Has Code

    You can also do

    then CONVERT(VARCHAR(9),ROUND(CEILING(Salary/1000)*1000,0)) -- the problem is here

    to make sure to remove extra .00

    Or 

    then CONVERT(VARCHAR(9),CONVERT(DECIMAL(9,0),CEILING(Salary/1000))*1000) -- the problem is here


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog