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.
Author |
Topic |
funk.phenomena
Posting Yak Master
121 Posts |
Posted - 2014-01-30 : 16:22:58
|
I have the following table:[CODE]SEQ DATE123 JAN-01-2013123 JAN-01-2013124 FEB-28-2013125 MAR-05-2013125 MAR-05-2013125 MAR-05-2013125 MAR-05-2013[/CODE]I need a script to pull the above records ONLY if the date repeats more than one within the same SEQ number. The proper script would output as follows:[CODE]SEQ DATE123 JAN-01-2013123 JAN-01-2013125 MAR-05-2013125 MAR-05-2013125 MAR-05-2013125 MAR-05-2013[/CODE]Any ideas? Thanks![CODE]SELECT SEQ,DATE FROM T1[/CODE] |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2014-01-30 : 16:47:30
|
[code]WITH cte(SEQ, DATE, cnt)AS ( SELECT SEQ, DATE, COUNT(*) OVER (PARTITION BY SEQ, DATE) AS cnt FROM dbo.Table1)SELECT SEQ, DATEFROM cteWHERE cnt >= 2;[/code] Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
funk.phenomena
Posting Yak Master
121 Posts |
Posted - 2014-01-31 : 09:51:46
|
Works!!!!!!!! Thx so much !!!!! |
|
|
|
|
|
|
|