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)
 Compare date

Author  Topic 

ledwallet
Starting Member

3 Posts

Posted - 2008-01-09 : 14:56:40
Hi,

I'm working with slq server 2005, i'm looking for a solution of my problem:

I have table "A" with with 7 row, one of them is a date format like "10/01/2008" and another table "B" with only the field date distinct from table "A", with tha same format.

I need to compare the two filds date for to know how many are double on the table "A".

I hope my explication is ok.

bye

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2008-01-09 : 15:27:54
Cant tell exactly what u r after, but one of these sounds like what u need...

SELECT datefield, count(datefield) c
FROM tableA
GROUP BY datefield
HAVING Count(datefield) > 1

SELECT a.datefield, count(a.datefield) c
FROM tableA a
JOIN tableB b
On a.datefield = b.datefield
GROUP BY a.datefield
HAVING Count(a.datefield) > 1
Go to Top of Page

ledwallet
Starting Member

3 Posts

Posted - 2008-01-09 : 15:54:24
Ok it's works!!!
Now i know for a determinate date how many them are, but...in the tableA i have a lot of rows, informations, but how can i put those in relation with those date?
I have to know now the full information from tableA.
quote:
Originally posted by russell

Cant tell exactly what u r after, but one of these sounds like what u need...

SELECT datefield, count(datefield) c
FROM tableA
GROUP BY datefield
HAVING Count(datefield) > 1

SELECT a.datefield, count(a.datefield) c
FROM tableA a
JOIN tableB b
On a.datefield = b.datefield
GROUP BY a.datefield
HAVING Count(a.datefield) > 1

Go to Top of Page

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2008-01-09 : 16:38:17
SELECT * FROM tableA where datefield in (SELECT datefield FROM tableA
GROUP BY datefield
HAVING Count(datefield) > 1)
Go to Top of Page
   

- Advertisement -