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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Non Null as an Aggregate

Author  Topic 

coagulance
Yak Posting Veteran

78 Posts

Posted - 2013-02-14 : 06:51:02
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?


SELECT
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
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-02-14 : 08:02:32
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
   

- Advertisement -