Solved

Case Statements

Posted on 2012-03-27
9
294 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

16 Experts available now in Live!

Get 1:1 Help Now