473,387 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using a max for the Added Date

347 100+
I have the following query:

Expand|Select|Wrap|Line Numbers
  1. SELECTSELECT FirstListing,OnCallStart,OnCallEnd, Initials
  2. FROM
  3. (
  4. SELECT
  5.     moncallAdd.FirstListing,
  6.     DATEADD(MINUTE, mOnCallAdd.StartOnCallTime,
  7.             DATEADD(DAY, mOnCallAdd.StartOnCallDate, '12/31/1899')) AS OnCallStart,
  8.     DATEADD(MINUTE, mOnCallAdd.duration,
  9.             DATEADD(MINUTE, mOnCallAdd.StartOnCallTime,
  10.                     DATEADD(DAY, mOnCallAdd.StartOnCallDate, '12/31/1899'))) AS OnCallEnd,
  11. Dateadd(second, moncalladd.Addtime,
  12. Dateadd (Minute, moncalladd.AddTime,
  13. Dateadd(Day, moncalladd.Adddate, '12/31/1899'))) as Added, 
  14. 'Added' As Activity,
  15. Initials
  16. FROM
  17.     mdr.dbo.mOnCallAdd
  18.      WHERE DATEADD(MINUTE, mOnCalladd.StartOnCallTime,
  19.      DATEADD(DAY, mOnCalladd.StartOnCallDate, '12/31/1899')) < GETDATE() 
  20.  AND 
  21.      DATEADD(MINUTE, mOnCalladd.duration,
  22.              DATEADD(MINUTE, mOnCalladd.StartOnCallTime,
  23.                      DATEADD(DAY, mOnCalladd.StartOnCallDate, '12/31/1899'))) >  GETDATE() and
  24.      mOnCallAdd.schedname =@schedname
  25.  
  26. UNION     
  27. SELECT
  28.     moncallDelete.FirstListing,
  29.     DATEADD(MINUTE, mOnCallDelete.StartOnCallTime,
  30.             DATEADD(DAY, mOnCallDelete.StartOnCallDate, '12/31/1899')) AS OnCallStart,
  31.     DATEADD(MINUTE, mOnCallDelete.duration,
  32.             DATEADD(MINUTE, mOnCallDelete.StartOnCallTime,
  33.                     DATEADD(DAY, mOnCallDelete.StartOnCallDate, '12/31/1899'))) AS OnCallEnd,
  34. Dateadd(second,moncalldelete.Addtime,
  35. Dateadd (Minute, moncalldelete.AddTime,
  36. Dateadd(Day, moncalldelete.Adddate, '12/31/1899'))) as Added, 
  37. 'Deleted' as Activity,
  38. Initials
  39. FROM
  40.       mdr.dbo.mOnCallDelete
  41.    WHERE DATEADD(MINUTE, mOnCallDelete.StartOnCallTime,
  42.      DATEADD(DAY, mOnCallDelete.StartOnCallDate, '12/31/1899')) < GETDATE() 
  43.  AND 
  44.      DATEADD(MINUTE, mOnCallDelete.duration,
  45.              DATEADD(MINUTE, mOnCallDelete.StartOnCallTime,
  46.                      DATEADD(DAY, mOnCallDelete.StartOnCallDate, '12/31/1899'))) >  GETDATE() and
  47.      mOnCallDelete.schedname = @schedname
  48. )t
  49. GROUP BY FirstListing,OnCallStart,OnCallEnd, Initials
  50. HAVING SUM(CASE WHEN Activity='Added' THEN 1 ELSE 0 END) >0
  51. AND SUM(CASE WHEN Activity='Deleted' THEN 1 ELSE 0 END) =0
  52.  
and need to add a MAX on the Added portion of the table, can someone please assist me on adding that?

Thank you

Doug
Sep 9 '11 #1
1 1286
ck9663
2,878 Expert 2GB
Max is in an aggregate function,you might need to revise your query if you want to use it only on the first portion of your SELECT.

Good Luck!!!


~~ CK
Sep 10 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Steve Elliott | last post by:
I have a query set up to gather together data between two specified dates. Shown in the query column as: Between #24/09/2004# And #01/10/2004# Is it possible to enter several different date...
3
by: hasanainf | last post by:
Hi all, What will be the best database design for an inventory control that uses expiry date for its products. Over a period of time, a particular product will have many expiry date and that...
2
by: Li Pang | last post by:
Hi I can't remember how to block using local date setting, in another word, I want ot force to use a specific date setting Anybody give a hand Thanks
11
by: Lauren Quantrell | last post by:
I already figured out (the hard way) I need to convert all my date parameters into USA format before executing my stored procedures where dates are used as parameters. (Format(StartDate, "m/d/yyyy...
2
by: The_Monkey | last post by:
I have created a form with a combo box to filter a subform using a date. The filter works great but not with dates starting with a 0 e.g 01/07/2006 I have set the format to short date for the...
3
by: JJ | last post by:
Here's the code. $link="http://xbox360cheat.org"; $close_date=$_POST; #last content change check if ($close_date == 0) $close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date...
5
by: Manogna | last post by:
hi! i got the following error while using the Date::Calc module in perl. plz help me.. the file is ex.pl contains code like this: use strict; use Date::Calc();
20
by: madhu3437 | last post by:
i am in big problem Under unix C Language i want return date format like MM/DD/YYYY this function should return above format . using system date calculate last 6 days mean clearly i am...
8
by: MLH | last post by:
Sometimes it works and sometimes it crashes. If I want "Today is " & Date$ & "." to appear in a query field, why might it work sometimes and not others? Would I be better to call a FN? Say,...
7
by: nhkam | last post by:
I am using MS Access 2007 I have a transaction table which holds all records with posting date on each of them. I used a make table query to find out the max date hold in the transaction table and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.