Solved

ms sql + a conditional where statement

Posted on 2006-06-10
3
212 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
[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
  • 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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.

734 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