Solved

Case Statements

Posted on 2012-03-27
9
292 Views
Last Modified: 2012-06-21
Hi,

I have this Case Statement, below, and I want it to return a specific numeric value.  Any thoughts?

thank.

case when d.product in ('DEBT', 'DISCOUNT', 'FRA', 'VARIANCE') and dspr.IsBuyOrSell = '1' then 'Buy'
when d.product in ('DEBT', 'DISCOUNT', 'FRA', 'VARIANCE') and dspr.IsBuyOrSell = '2' then 'Sell'  
when d.product in ('EQUITYSWAP', 'CREDITDEFAULT') and dspr.IsBuyOrSell = '1' then 'Recieve'--dsr.currentrate
when d.product in ('EQUITYSWAP', 'CREDITDEFAULT') and dspr.IsBuyOrSell = '2' then 'Pay'--dsp.currentrate  
when dsp.side = 'R' then 'Recieve'-- dsr.currentrate  
when dsp.side = 'P' then  'Pay' --dsp.currentrate  
when d.product in ('CAP','EUITYOPTION') then 'Pay' else 'Option' end

dsp.currentrate  [pay rate]
0
Comment
Question by:fundsf
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 8

Assisted Solution

by:gpizzuto
gpizzuto earned 167 total points
ID: 37773460
Why don't you use a pre-defined table containing the values of the fields you want to match
and JOIN it to your table ?
0
 
LVL 6

Assisted Solution

by:SJCFL-Admin
SJCFL-Admin earned 166 total points
ID: 37773472
If you wanted it to return a numeric value then i would expect to see a numeric expression after the 'then' specifying how the returned numeric value should be computed.  but perhaps I am misunderstanding and you need to provide additional information as to what your requirements are..
0
 
LVL 51

Accepted Solution

by:
HainKurt earned 167 total points
ID: 37773581
here is numeric values :)

case 
when d.product in ('DEBT', 'DISCOUNT', 'FRA', 'VARIANCE') and dspr.IsBuyOrSell = '1' then 1
when d.product in ('DEBT', 'DISCOUNT', 'FRA', 'VARIANCE') and dspr.IsBuyOrSell = '2' then 2
when d.product in ('EQUITYSWAP', 'CREDITDEFAULT') and dspr.IsBuyOrSell = '1' then 3
when d.product in ('EQUITYSWAP', 'CREDITDEFAULT') and dspr.IsBuyOrSell = '2' then 4
when dsp.side = 'R' then 3
when dsp.side = 'P' then  4
when d.product in ('CAP','EUITYOPTION') then 4
else 0
end 

Open in new window

0
 

Author Comment

by:fundsf
ID: 37773670
base on the case i want it to return the dsp.currentrate...
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 6

Expert Comment

by:SJCFL-Admin
ID: 37773725
The equivalent to a case in SSRS is the SWITCH.. Is that what you wanted?

=SWITCH (  Fields!d.product='DEBT'      AND dspr.IsBuyOrSell = '1', 1,
           Fields!d.product='DISCOUNT'  AND dspr.IsBuyOrSell = '1', 1,
           Fields!d.product='FRA'       AND dspr.IsBuyOrSell = '1', 1,
           Fields!d.product='DEBT'      AND dspr.IsBuyOrSell = '1', 1,
           Fields!d.product='DEBT'      AND dspr.IsBuyOrSell = '1', 1,
           Fields!d.product='DEBT'      AND dspr.IsBuyOrSell = '2', 2,
           Fields!d.product='DISCOUNT'  AND dspr.IsBuyOrSell = '2', 2,
           Fields!d.product='FRA'       AND dspr.IsBuyOrSell = '2', 2,
           Fields!d.product='DEBT'      AND dspr.IsBuyOrSell = '2', 2,
           Fields!d.product='DEBT'      AND dspr.IsBuyOrSell = '2', 2,
           Fields!d.product='EQUITYSWAP'    AND dspr.IsBuyOrSell = '1', 3,
           Fields!d.product='CREDITDEFAULT' AND dspr.IsBuyOrSell = '2', 4,
           Fields!d.product='EQUITYSWAP'    AND dspr.IsBuyOrSell = '1', 3,
           Fields!d.product='CREDITDEFAULT' AND dspr.IsBuyOrSell = '2', 4,
           True, 0)
0
 
LVL 6

Expert Comment

by:SJCFL-Admin
ID: 37773733
oops missing equivalents for

when dsp.side = 'R' then 3
when dsp.side = 'P' then  4
when d.product in ('CAP','EUITYOPTION') then 4


but I think you get the idea...  And setting up a table and doing a join is looking really really good to me... lol
0
 
LVL 8

Expert Comment

by:gpizzuto
ID: 37773810
@SJCFL-Admin: really happy you appreciated it (joining with the table)
In this way changes to logic can be easily managed
0
 
LVL 6

Expert Comment

by:SJCFL-Admin
ID: 37925665
fundsf,

Did any of the suggestions help?  Or did you decide on an alternate solution?  It has been a while and I am curious to know how this was finally resolved....
0
 

Author Closing Comment

by:fundsf
ID: 37948523
Thnaks for all the help!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MS SQL script conversion error in dates 3 20
Mssql SQL query 14 28
SQL Update Query - What's wrong with this. 18 14
Update in Sql 7 12
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now