sql - TSQL How to convert varchar to numeric on a Case statement -


here's query. want take [market value] case expression , add 'certified' case expression.

  declare @as_of_date date set @as_of_date = '01/27/2016'  select     'as of date'    = @as_of_date    ,   a.acctnbr ,   a.cusipnumber ,   b.desc1 ,   b.symbol ,   'sec type'  = rtrim (b.sectype)+b.cmpqual+b.secqual ,   a.accttype ,   a.locmemo ,   a.begsdquantity ,   b.closeprice ,   [market value]  = (case when rtrim (b.sectype)+b.cmpqual+b.secqual in ('a01', 'a02', 'b01', 'b02', 'c01', 'c02', 'f01', 'f02', 'f03',     'f04', 'f05', 'f06', 'g01', 'g02', 'g03', 'g04', 'h01', 'h02', 't01', '501', '502', '503', '504', '601', '602', '603')     convert(decimal(25,3),a.begsdquantity * b.closeprice)     else convert(decimal(25,3),a.begsdquantity /100 * b.closeprice) end) ,   'total debit'   = c.settlebalance ,   'hypothecation' = c.settlebalance * 1.40 ,   'certified'     =  (case when ((('market value') < (c.settlebalance * 1.40)) or                         (c.settlebalance * 1.40 = '0.00')) 'certified'                         else 'exception'                         end)  vw_table inner join vw_table b on a.firmcusipid = b.firmcusipid     , @as_of_date between a.effectivedate , a.expirationdate     , @as_of_date between b.effectivedate , b.expirationdate inner join vw_table c on a.firmaccountid = c.firmaccountid     , @as_of_date between c.effectivedate , c.expirationdate 

when run query above error message: "error converting data type varchar numeric"

any thought on how can fix this?

thanks,

here

case when ((('market value') < (c.settlebalance * 1.40)) 

you comparing varchar value "market value" against numeric value. expect?

might be, should put closing paranthesis right behind "a.begsdquantity", don't know data types there...:

convert(decimal(25,3),a.begsdquantity) * b.closeprice 

but without knowledge of table's declarations reading magic glass bulb...


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -