Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Explain code please

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2011-12-09 : 12:06:24


I get min and max mixed up.


SELECT
doc,
COUNT(*) AS cnt
FROM
(

SELECT [doc],fo, clmssn, COUNT(*) AS cnt,--,
Age = Datediff(day,max(filedate), getdate()),
FileDate = max(FileDate),
MIN(ddsrcpt) AS ddsrcpt,
DDSAge = Datediff(day,max(ddsrcpt), getdate()),
Title = case when min(Title) <> max(Title) then 'Concurr' else min(Title) end
FROM pendingdds p
join Offices.dbo.OfficeCodes d
on d.officecode = p.doc
where doc in ('S55')
Group By
fo, doc, clmssn
) AS T
GROUP BY
doc

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-09 : 12:22:02
sorry didnt understand whats the issue

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2011-12-09 : 12:52:03
Can you explain what this code is doing? or tell me the difference between min and max in sql.

When dealing with two dates:

12/03/2011 and 11/03/2011 which one would be min? I want to make sure I'm getting the right date in my query.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-09 : 13:01:48
min will be minimum of dates ie 11/03/2011 and max will return other date. thats straightforward isnt it?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2011-12-09 : 14:23:34
Yes it is thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-10 : 07:41:30
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -