Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Case Statements

Posted on 2012-03-27
9
295 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:fundsf
ID: 37773670
base on the case i want it to return the dsp.currentrate...
0
 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
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 …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

791 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