Solved

ms sql + a conditional where statement

Posted on 2006-06-10
3
204 Views
Last Modified: 2008-02-01
Is it possible to have a conditional where statement if so how.

ie if a value in the select statement equals a something then the part of the where statement would equal one thing if not another

this is what i tried.
WHERE completed = 1
AND CASE WHEN touch_reason in (19,20) THEN
DATEDIFF(hour, cdol.maxdate , getDate()) > 12
ELSE
DATEDIFF(hour, cdol.maxdate , getDate()) > 0
END
0
Comment
Question by:dkilby
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 16878612
Hi dkilby,

WHERE completed = 1 AND
    ((touch_reason IN (19, 20) AND DATEDIFF(hour, cdol.maxdate, GETDATE()) > 12) OR
    (touch_reason NOT IN (19, 20) AND DATEDIFF(hour, cdol.maxdate, GETDATE()) > 0))

Regards,

Patrick
0
 

Author Comment

by:dkilby
ID: 16878637
thank you - worked great
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 16878951
dkilby,

You're welcome :)

Regards,

Patrick
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

708 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

17 Experts available now in Live!

Get 1:1 Help Now