x
login about faq Site discussion (meta-askssc)

Multi Conditional Case Statement

I need to come up with a case statement and I'm not sure if I should do it as part of the table join or in my select statement.

Bur when a Status is Price Reduced then I need to pull a price that was effective the day after an issue was closed.

If the Status was not equal to "Price Reduced" I need to take the first price change in the next 30 days and use that value.

If there was no difference, then I need to use "Null"

Any help you can provide would be great - Here is what I have so far and I tried it in the select statement but I get errors when I try to get the statement to evaluate the date range between.

CASE WHEN a.STATUS = 'Price reduced' 
       THEN DATEADD(d, 1,a.CLOSE_DATE) IS  BETWEEN p.PRC_EFF_DT AND p.PRC_END_DT
       CASE WHEN a.Status != 'Price reduced' 
       THEN DATEADD(d, 30, a.CLOSE_DATE) IS  BETWEEN  p.PRC_EFF_DT AND p.PRC_END_DT
    ELSE NULL END AS p.PRICE,
more ▼

asked Mar 22 '11 at 01:53 PM in Default

siera_gld gravatar image

siera_gld
946 58 72 74

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

I try to keep the JOIN ON criteria limited to just those things that are needed to make the right matches between table rows, and do the filtering in the WHERE clause - it seems more logical that way, and, I think, makes for more maintainable code.

I'm sure this discussion has been had elsewhere here...

http://www.google.co.uk/search?q=%2Bjoin+%2Bwhere+%2Bsite%3Aask.sqlservercentral.com

more ▼

answered Mar 22 '11 at 02:06 PM

ThomasRushton gravatar image

ThomasRushton ♦
30.1k 7 10 40

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x916
x36

asked: Mar 22 '11 at 01:53 PM

Seen: 1219 times

Last Updated: Mar 22 '11 at 01:53 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.