January 19, 2010 at 12:22 pm
Hi from the temp table below I would like to see related orders that were actioned by different employees. So for RelatedID 1 employee B & C both actioned that related order. How would I be able to pick instances of this out...
Thanks in advance for your help.
IF OBJECT_ID('tempdb..#A') IS NOT NULL DROP TABLE #A;
Create table #A(RelatedID int, EmpID varchar(10))
INSERT INTO #A VALUES (0, 'A')
INSERT INTO #A VALUES (1, 'B')
INSERT INTO #A VALUES (1, 'C')
INSERT INTO #A VALUES (2, 'D')
INSERT INTO #A VALUES (2, 'D')
INSERT INTO #A VALUES (4, 'E')
Select * from #A
January 19, 2010 at 12:30 pm
You have verbalized the desired output, could you show us what the final result of the query would look like? A picture is like a thousand words. Seeing what you want to accomplish helps a lot.
January 19, 2010 at 12:35 pm
Lynn Pettis (1/19/2010)
You have verbalized the desired output, could you show us what the final result of the query would look like? A picture is like a thousand words. Seeing what you want to accomplish helps a lot.
Sure Lynn, from the temp table the only values I would like to see are relatedID: 1 because they have the same id but different employees: 'B' & 'C'
RElatedID EmpID
1 B
1 C
Hope this makes more sense...Thanks again.
January 19, 2010 at 12:36 pm
First of all: thank you for providing ready to use test data!! Well done! 😀
Would something like the following help?
;WITH cte AS
(
SELECT RelatedID
FROM #A
GROUP BY RelatedID
HAVING count(DISTINCT EmpID) >1
)
SELECT #A.* FROM #A INNER JOIN cte ON #A.RelatedID = cte.RelatedID
January 19, 2010 at 10:40 pm
Marcus Farrugia (1/19/2010)
Hi from the temp table below I would like to see related orders that were actioned by different employees. So for RelatedID 1 employee B & C both actioned that related order. How would I be able to pick instances of this out...Thanks in advance for your help.
IF OBJECT_ID('tempdb..#A') IS NOT NULL DROP TABLE #A;
Create table #A(RelatedID int, EmpID varchar(10))
INSERT INTO #A VALUES (0, 'A')
INSERT INTO #A VALUES (1, 'B')
INSERT INTO #A VALUES (1, 'C')
INSERT INTO #A VALUES (2, 'D')
INSERT INTO #A VALUES (2, 'D')
INSERT INTO #A VALUES (4, 'E')
Select * from #A
Lutz has the right idea with his code but let me ask you... what do you want done with the 2 instances of 2 D? Supress or return?
--Jeff Moden
Change is inevitable... Change for the better is not.
January 20, 2010 at 7:35 am
Hi Jeff, Lutz and Lynn...thanks for taking the time to reply...What I'd like to do is create a report for our process team that takes related orders identified by a related order id that were actioned by different employees, so that they can minimze touches on related product orders by multiple employees. So I'm actually joining a couple of tables from a related orders table and an employee workload table to get all related orders and which employees completed the order. So I would like to return the all jobs with the same related order id that have different employee numbers. Hope this makes more sense.
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply