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
 If else statement with counts

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2011-11-09 : 14:50:38
How do I write a query to get this

doc cnt
S55 4

I have two of the same records in the table but their Titles are different so instead of the count coming out to 5 how do I get the count to come out to 4

Here's the table info:


CREATE TABLE [dbo].[Test](
[FO] [varchar](3) NULL,
[doc] [varchar](4) NULL,
[clm] [char] (6) NULL,
[cos] [char] (6) NULL,
[FileDate] [char] (30) NULL,
[DDSRcpt] [char](30) NULL,
[Title] [varchar](3) NULL

) ON [PRIMARY]

insert into Test
select '311', 'S55', '458963', '458963', '12/14/2010', '05/23/2011', 'T2' union all
select '311', 'S55', '256983', '256983', '11/03/2010', '07/05/2011', 'T16' union all
select '311', 'S55', '129653', '129653', '01/28/2011', '04/20/2011', 'T16' union all
select '311', 'S55', '129653', '129653', '01/28/2011', '04/20/2011', 'T2' union all
select '315', 'S55', '457884', '457884', '10/01/2010', '05/23/2011', 'T16'


The bold is the same but I want it to be counted as one record.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-11-09 : 15:10:17
Maybe this?

select COUNT(distinct FO+DOC+CLM+[COS]+FileDate )
from test

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2011-11-09 : 18:26:42
Thanks that worked!
Go to Top of Page
   

- Advertisement -