Solved

Case Statements

Posted on 2012-03-27
9
297 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
[X]
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
  • 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 53

Accepted Solution

by:
Huseyin KAHRAMAN 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How come this XML node is not read? 3 54
Split string into 3 separate fields 5 36
T-SQL: I need to add an index on a field 5 50
Tracking Problematic Page Splits 1 50
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 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