Henrique Melicio
Henrique Melicio

Reputation: 79

How to count the amount of dates on field?

I need to count the number of dates as example, I would like my results are: 14.

Im my example results, I'am showing a select with distinct, I have same date repeated several times, however count quantity the lines dont solv my problem.

How do I select this in SQL Server?

fk_date
2016-08-01
2016-08-02
2016-08-03
2016-08-04
2016-08-05
2016-08-08
2016-08-09
2016-08-10
2016-08-11
2016-08-12
2016-08-15
2016-08-16
2016-08-17
2016-08-18

Upvotes: 0

Views: 41

Answers (1)

fedorqui
fedorqui

Reputation: 289675

You can use COUNT(DISTINCT) for this:

SELECT 
   COUNT (DISTINCT fk_date)
FROM 
   table

As described in the reference for COUNT():

DISTINCT
Specifies that COUNT returns the number of unique nonnull values.

Upvotes: 1

Related Questions