Solved

Case Statment

Posted on 2008-10-30
3
161 Views
Last Modified: 2012-05-05
I keep getting an error in this case statement.  Any help would be appreciated:


CASE
	WHEN DATEDIFF(dd,AL2.AU_TIME,AL1.AU_TIME)> 0 THEN DATEDIFF(dd,AL2.AU_TIME,AL1.AU_TIME) "DAYS_IN_STATUS"
	WHEN DATEDIFF(hh,AL2.AU_TIME,AL1.AU_TIME)> 0 
		 AND DATEDIFF(dd,AL2.AU_TIME,AL1.AU_TIME)< 0 THEN DATEDIFF(hh,AL2.AU_TIME,AL1.AU_TIME) "DAYS_IN_STATUS"
	WHEN DATEDIFF(mm,AL2.AU_TIME,AL1.AU_TIME)> 0
		 AND DATEDIFF(dd,AL2.AU_TIME,AL1.AU_TIME)< 0
         AND DATEDIFF(hh,AL2.AU_TIME,AL1.AU_TIME) < 0 THEN DATEDIFF(mm,AL2.AU_TIME,AL1.AU_TIME) "DAYS_IN_STATUS"
	WHEN DATEDIFF(ss,AL2.AU_TIME,AL1.AU_TIME)> 0 
		 AND DATEDIFF(dd,AL2.AU_TIME,AL1.AU_TIME)< 0
         AND DATEDIFF(hh,AL2.AU_TIME,AL1.AU_TIME) < 0
         AND DATEDIFF(mm,AL2.AU_TIME,AL1.AU_TIME) < 0 THEN DATEDIFF(ss,AL2.AU_TIME,AL1.AU_TIME) "DAYS_IN_STATUS" 	
END AS ID

Open in new window

0
Comment
Question by:daintysally
[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 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 22843523
select CASE
        WHEN DATEDIFF(dd,AL2.AU_TIME,AL1.AU_TIME)> 0 THEN DATEDIFF(dd,AL2.AU_TIME,AL1.AU_TIME)
        WHEN DATEDIFF(hh,AL2.AU_TIME,AL1.AU_TIME)> 0
                 AND DATEDIFF(dd,AL2.AU_TIME,AL1.AU_TIME)< 0 THEN DATEDIFF(hh,AL2.AU_TIME,AL1.AU_TIME)
        WHEN DATEDIFF(mm,AL2.AU_TIME,AL1.AU_TIME)> 0
                 AND DATEDIFF(dd,AL2.AU_TIME,AL1.AU_TIME)< 0
         AND DATEDIFF(hh,AL2.AU_TIME,AL1.AU_TIME) < 0 THEN DATEDIFF(mm,AL2.AU_TIME,AL1.AU_TIME)
        WHEN DATEDIFF(ss,AL2.AU_TIME,AL1.AU_TIME)> 0
                 AND DATEDIFF(dd,AL2.AU_TIME,AL1.AU_TIME)< 0
         AND DATEDIFF(hh,AL2.AU_TIME,AL1.AU_TIME) < 0
         AND DATEDIFF(mm,AL2.AU_TIME,AL1.AU_TIME) < 0 THEN DATEDIFF(ss,AL2.AU_TIME,AL1.AU_TIME)      
END AS ID
from tablename
0
 

Author Comment

by:daintysally
ID: 22843529
I'm trying to compare records against one another with different date timestamps.
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 22843776
You're statement was great...just needed to take out your "alias"
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

696 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