Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am joining the closed tickets table to itself for the purpose of showing devices that had trouble tickets in March and in April.See sample result set:PRINEID ClosedFirstMonth ClosedSecondMonth FirstOutage SecondOutage
GWAN-ARGBUE0282-2011715E001 2014-03-14 00:00:00.000 2014-04-08 00:00:00.000 16 247
GWAN-ARGBUE0282-2011715E001 2014-03-14 00:00:00.000 2014-04-17 00:00:00.000 16 454
GWAN-ARGBUE0282-2011715E001 2014-03-14 00:00:00.000 2014-04-25 00:00:00.000 16 212
GWAN-ARGBUE0282-2011715E001 2014-03-18 00:00:00.000 2014-04-08 00:00:00.000 145 247
GWAN-ARGBUE0282-2011715E001 2014-03-18 00:00:00.000 2014-04-17 00:00:00.000 145 454
GWAN-ARGBUE0282-2011715E001 2014-03-18 00:00:00.000 2014-04-25 00:00:00.000 145 212
GWAN-ARGBUE0324-2516241E001 2014-03-18 00:00:00.000 2014-04-23 00:00:00.000 31 50
GWAN-ARGBUE0324-2516241E001 2014-03-12 00:00:00.000 2014-04-23 00:00:00.000 1 50

What I have tried:

Joined the closed tickets table to itself (aliases a & b) using a date range for the two months involved trying both inner and left outer joins.
Posted
Comments
ZurdoDev 15-Feb-16 12:15pm    
One way is to use DISTINCT. Where exactly are you stuck?
Member 12328879 15-Feb-16 12:39pm    
DISTINCT does not work in this instance as each output record is distinct. considering looping logic (WHILE..., etc.) on the PRINEID field which repeats.
ZurdoDev 15-Feb-16 12:40pm    
If each output record is distinct then you don't have repetitive values. You need to be more clear on what you need.
Richard Deeming 15-Feb-16 13:43pm    
We can't see the structure of your tables; we can't see the data in those tables; and we can't see the query you're running.

We have no information with which to help you.

Create a small SQL Fiddle[^] to demonstrate the problem. Then click "Improve question" and add the link to your SQL Fiddle to the question.
GuyThiebaut 17-Feb-16 8:23am    
GWAN-ARGBUE0282-2011715E001 2014-03-14 00:00:00.000 2014-04-08 00:00:00.000 16 247
GWAN-ARGBUE0282-2011715E001 2014-03-14 00:00:00.000 2014-04-17 00:00:00.000 16 454


The two values above are different - your query is behaving correctly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900