Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

help with simple CASe statement

$
0
0

I have a simple case statement I am looking for a little assistance with if possible?

I need to make the WHERE clause of my statement dynamic in so much as, dependant upon the value of a column, another column is evaulated differently.

so if I was writing this as an if..then it would go

if col1 = 'Weekly' then
Statement = ""
else
Statement = ""
end if

Here's the statement

SELECT    TradeCustomerID, BusinessName FROM  Customers_Trade WHERE AutoStatement = 'Manual' AND (CASE AutoStatementFrequency  WHEN  'Weekly' THEN (DateDiff(d,AutoStatementLastDate, getdate()) > 7) ELSE ((DateDiff(m,AutoStatementLastDate, getdate()) > 0 AND Day(getdate()) > Day(AutoStatementLastDate)) END)

Anyone help me get to the bottom of this please?

Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>