Solved

ms sql + a conditional where statement

Posted on 2006-06-10
3
210 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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Re-appearing SQL Server Agent jobs 7 30
Database ERD 4 31
SQL Log size 3 19
Compare a numeric value to a varchar w/o getting an error 4 21
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

828 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