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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Non Null as an Aggregate
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

78 Posts

Posted - 02/14/2013 :  06:51:02  Show Profile  Reply with Quote
I need to insert tqo more colums in the below query where instead of Max or Min , I need to get the first non null value. Can any some one help?

t1.ProcessSegmentS95Id as 'Segment',t2.ProcessSegmentS95Id as 'ChildSegment',
MIN(t1.StartTime) as 'SegmentStartTime' , MAX(t1.EndTime)as 'SegmentEndTime',
MIN(t2.StartTime) as 'ChildSegmentStartTime' , MAX(t2.EndTime)as 'ChildSegmentEndTime'

 FROM (SELECT * FROM [SOADB].[dbo].[SegmentResponse] where Depth = 0 ) t1 
  INNER join 
  (SELECT * FROM [SOADB].[dbo].[SegmentResponse] where Depth=1) t2
  on t1.SegmentResponseId = t2.ParentSegmentResponseId
  group by t1.ProcessSegmentS95Id ,t2.ProcessSegmentS95Id
   order by t1.ProcessSegmentS95Id ,t2.ProcessSegmentS95Id

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 02/14/2013 :  08:02:32  Show Profile  Reply with Quote
When you say "first non null value", that implies an ordering scheme for the rows other than StartTime. What is that ordering scheme?
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000