Advertisement

08.28.2008 at 10:00AM PDT, ID: 23686299
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1

Microsoft SQL query help: Find max date based on conditions, else return NULL

Asked by Pharmica in SQL Query Syntax, MS SQL Server, SQL Server 2005

Tags:

Greetings Experts,

I have previously opened this question before and closed it thinking it was working.  Apparently it isnt.
Here is the orginal question;

http://www.experts-exchange.com/Database/Oracle/PL_SQL/Q_23622144.html

I will explain what I am attempting to accomplish.  I am trying to write a query that will determine the max date of columm ONLY if all the dates are present for the rest of the grouping.  If there is a single NULL, then return NULL.

For example
StudyID          SiteCertDate       SiteCertType
   A                 01/01/2008           IRB Approval
   A                 02/02/2008           Brochure
    A                   NULL                 1592
   B                  05/01/2008          IRB Approval
   B                    NULL                  Brochure
   B                    NULL                  1592
    C               04/01/2008              IRB Approval
   C              03/01/2008             Brochure
   C              05/01/2008               1592

Using this example, the results would look like this

StudyID          SiteCertDate      
    A                    NULL
    B                    NULL
    C                05/01/2008   <---MAX date of grouping StudyID=C

Below is the query I have been working with but for what ever reason I keep getting a result set that shows the max date even if any of the other dates are NULL.  

select
case when sum(case when isnull(sinv.sitecertvaluedate,'19000102') = '19000102' then 1 else 0 end)  =0 then max(sinv.sitecertvaluedate) else NULL end as 'Sitecertdate',
sinv.stdinv_id

FROM trialworksIkaria.dbo.tbl_sitecertstdinv SINV
left outer join trialworksikaria.dbo.tbl_sitecertstudy S
on S.sitecertstudy_ID = Sinv.sitecertstudy_ID

Where
S.sitecertname = "Brochure "  or  s.sitecertname ="IRB Approval" or  s.sitecertname ="1592"

group by
sinv.stdinv_id















Start Free Trial
[+][-]08.28.2008 at 11:32AM PDT, ID: 22338168

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.28.2008 at 11:47AM PDT, ID: 22338357

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.28.2008 at 11:49AM PDT, ID: 22338381

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.28.2008 at 11:52AM PDT, ID: 22338416

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: SQL Query Syntax, MS SQL Server, SQL Server 2005
Tags: Microsoft SQL
Sign Up Now!
Solution Provided By: mwvisa1
Participating Experts: 3
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628