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
 Help with query

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2012-01-17 : 09:17:13
I have this query which works:




Select p.DOC,
p.Fo,
p.CLM,

Age = Datediff(day,max(p.filedate), getdate()),
FileDate = max(FileDate),
Min(ddsrpt) AS DDSReceipt,
DDSAge = Datediff(day,min(p.ddsrpt), getdate()),
Title = case when min(p.Title) <> max(p.Title) then 'Concurr' else min(p.Title) end
From testtable p
where p.doc ='s09'
Group By p.doc, p.fo,p.DOC, p.CLM
order by age desc



This produces this table


Doc FO CLM Age FileDate DDSReceipt DDSAge Title
S09 267 052582 277 4/15/2011 4/15/2011 277 Concurr
S09 267 084813 259 5/3/2011 5/3/2011 259 T16
S09 029 116632 257 5/5/2011 5/5/2011 257 T2
S09 268 116632 257 5/5/2011 5/5/2011 257 T16
S09 C80 028703 251 5/11/2011 5/11/2011 251 T16


How do I set it up so Concurr can show for clm 116632 As you see both T2 and T16 are showing up but it should say concurr as well.

The FO numbers are different so how could I make it come out this way?


Doc FO CLM Age FileDate DDSReceipt DDSAge Title
S09 267 052582 277 4/15/2011 4/15/2011 277 Concurr
S09 267 084813 259 5/3/2011 5/3/2011 259 T16
S09 029 116632 257 5/5/2011 5/5/2011 257 Concurr
S09 C80 028703 251 5/11/2011 5/11/2011 251 T16




I would need to add someting that if min(title) <> max(title) then Concurr and if min(title) <> max(title) and FO <> FO then select one record and make it concurr. Is this possible?

JJ297
Aged Yak Warrior

940 Posts

Posted - 2012-01-17 : 09:26:53
Sorry here's the table info:



CREATE TABLE [dbo].[testtable](
[doc] [varchar](3) NULL,
[fo] [varchar](3) NULL,
[clm] [char] (6) NULL,
[cos] [char](6) NULL,
[Filedate] [char](30) NULL,
[ddsrpt] [char](30) NULL,
[title] [varchar] (3) NULL,
) ON [PRIMARY]

insert into testtable
select 'S09', 'C80', '028703', '028703', '5/11/2011', '5/11/2011', 'T16' union all
select 'S09', '267', '052582', '052582', '4/15/2011', '4/15/2011', 'T16' union all
select 'S09', '267', '052582', '052582', '4/15/2011', '4/15/2011', 'T2' union all
select 'S09', '267', '084813', '084813', '5/3/2011', '5/3/2011', 'T16' union all
select 'S09', '029', '116632', '116632', '5/5/2011', '5/5/2011', 'T2' union all
select 'S09', '268', '116632', '116632', '5/5/2011', '5/5/2011', 'T16'
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-01-17 : 09:38:27
Don't group by FO if you don't want a different row for each different FO.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2012-01-17 : 12:11:35
That's perfect! Please explain.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-17 : 13:19:59
What's Perfect?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2012-01-17 : 13:21:20
Not grouping with FO gave me my intended results.
Go to Top of Page
   

- Advertisement -