Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Case of a case???

Author  Topic 

duhaas
Constraint Violating Yak Guru

310 Posts

Posted - 2010-07-08 : 17:38:02
Have the following:

select top 100 m.RecordEntryNumber                                                            as External_ID,
m.TaxCode,
m.BankNumber + m.AccountNumber as Portfolio,
COALESCE(b.TradeDate, b.SettlementDate, m.PostingDate) as Effective_Date,
b.TradeDate,
b.SettlementDate,
m.PostingDate,
cast(replace(replace(b.CommissionAmount, '+', ''), '-', '') as DECIMAL(18, 5)) as CommissionAmount,
cast(replace(replace(b.OtherCosts, '+', ''), '-', '') as DECIMAL(18, 5)) as SEC_Fee,
case
when m.UnitsHeld like '%-' then '-' + cast(cast(replace(replace(m.UnitsHeld, '+', ''), '-', '') as DECIMAL(18, 3)) as VARCHAR)
else '+' + cast(cast(replace(replace(m.UnitsHeld, '+', ''), '-', '') as DECIMAL(18, 3)) as VARCHAR)
end as Quantity,
case
when m.UnitsHeld like '%-' then '-' + cast(cast(replace(replace(m.PrincipalCashAmount, '+', ''), '-', '') as DECIMAL(18, 3)) as VARCHAR)
else '+' + cast(cast(replace(replace(m.PrincipalCashAmount, '+', ''), '-', '') as DECIMAL(18, 3)) as VARCHAR)
end as Total_Amount,
m.PrincipalCashAmount,
m.IncomeCashAmount,
--cast(replace(replace(m.PrincipalCashAmount, '+', ''), '-', '') as DECIMAL(18, 2)) as Total_Amount,
'USD' as Cash_Balance,
m.SecurityNumber as [Security],
'USD' as Currency_ID,
'' as Code,
'' as Reversal,
'' as [Status],
'' as Backdated
from MV_XIP_Transaction_MoneyDataRecord m
left join MV_XIP_Transaction_BrokerDataRecord b
on b.ID = m.ID
where m.AccountNumber in (select distinct account_number
from IMCWharehouse..account_detail
where ( portfolio_manager = 'AWS'
or administrator in ( 'SMM', 'DJG' ) )
and DD1 is not null)


for total amount, i want to use m.PrincipalCashAmount is it returns all 0's. Not sure what the best way to go about that is

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2010-07-08 : 18:36:59
I'm not sure what you are asking for...

=======================================
A couple of months in the laboratory can save a couple of hours in the library. -Frank H. Westheimer, chemistry professor (1912-2007)
Go to Top of Page

duhaas
Constraint Violating Yak Guru

310 Posts

Posted - 2010-07-09 : 00:09:39
quote:
Originally posted by Bustaz Kool

I'm not sure what you are asking for...

=======================================
A couple of months in the laboratory can save a couple of hours in the library. -Frank H. Westheimer, chemistry professor (1912-2007)



With the case statement, not sure how to use that column m.pricipalcashamount if that case statement returns a 0
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2010-07-09 : 19:38:03
Use a nested CASE:
[CODE]
case
when ...
then
case
when ... = 0
then blah, blah, blah
else yadda, yadda, yadda
end
else ...
end[/CODE]

=======================================
A couple of months in the laboratory can save a couple of hours in the library. -Frank H. Westheimer, chemistry professor (1912-2007)
Go to Top of Page
   

- Advertisement -