I have two tables joined on CallGUID
[tt]
TABLE1
CallType
CallDate
CallNumber
CallDuration
CallGUID
CallType CallDate CallNumber CallDuration CallGUID
1 08/12/2010 09:20:38 1234561234 100 8C2166F4
0 08/12/2010 11:20:38 1234561236 90 8C2199F6
TABLE2
CallExt - shows incoming line (<100) and answering extention
CallGUID
CallExt CallGUID
7 8C2166F4
1000 8C2166F4
1700 8C2166F4
20 8C2199F6
1810 8C2199F6
[/tt]
I would like the output table to be
[tt]
OUTTABLE
CallType
CallDate
CallNumber
CallDuration
CallExt - answering extention
CallExt - incoming line
CallType CallDate CallNumber CallDuration CallExt CallExt
1 08/12/2010 09:20:38 1234561234 100 1000 7
1 08/12/2010 09:20:38 1234561234 100 1700 7
0 08/12/2010 11:20:38 1234561236 90 1810 20
[/tt]
Thus separating the incoming line from the answering extention.
Note the incoming line is less than 100.
I think a cte will take care of this but I still learning how to use them correctly.
My current idea
Thank you for your help.
djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
[tt]
TABLE1
CallType
CallDate
CallNumber
CallDuration
CallGUID
CallType CallDate CallNumber CallDuration CallGUID
1 08/12/2010 09:20:38 1234561234 100 8C2166F4
0 08/12/2010 11:20:38 1234561236 90 8C2199F6
TABLE2
CallExt - shows incoming line (<100) and answering extention
CallGUID
CallExt CallGUID
7 8C2166F4
1000 8C2166F4
1700 8C2166F4
20 8C2199F6
1810 8C2199F6
[/tt]
I would like the output table to be
[tt]
OUTTABLE
CallType
CallDate
CallNumber
CallDuration
CallExt - answering extention
CallExt - incoming line
CallType CallDate CallNumber CallDuration CallExt CallExt
1 08/12/2010 09:20:38 1234561234 100 1000 7
1 08/12/2010 09:20:38 1234561234 100 1700 7
0 08/12/2010 11:20:38 1234561236 90 1810 20
[/tt]
Thus separating the incoming line from the answering extention.
Note the incoming line is less than 100.
I think a cte will take care of this but I still learning how to use them correctly.
My current idea
Code:
SELECT A.CallType, A.CallDate, A.CallNumber, A.CallDuration, B.CallExt, C.CallExt
FROM TABLE1 A
INNER JOIN (
SELECT CallExt, CallGUID
FROM TABLE2
WHERE CAST(CallExt AS INT) > 100
) AS B
ON A.CallGUID = B.CallCUID
INNER JOIN (
SELECT CallExt, CallGUID
FROM TABLE2
WHERE CAST(CallExt AS INT) < 100
) AS C
ON A.CallGUID = C.CallCUID
djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!