I've spent hours researching answers to what should be a very simple T-SQL statement.
Here is the situation. I'm tyring to report over a help desk data base. I have one table (calllog) that contains basic non-repeating information about a trouble ticket and another transactional table (Asgnmnt) which contains various assignments to different people to fix the problem. I'm simply trying to determine the last assigment in the Asgnmnt table, link it with the call log file and use that data in the outer select to do more data reporting. The Asgnmnt table contains a field call HEATSeq. The hightest HEATSeq for a given CallID will be the last assignment. Here is my T-SQL statement and error.
SELECT
Callid,
Priority,
RecvdDate,
RecvdTime,
ClosedDate,
ClosedTime,
CustID,
CallType,
CallDesc,
HeatSEQ#
FROM
(Select
a.Callid,
a.Priority,
a.RecvdDate,
a.RecvdTime,
a.ClosedDate,
a.ClosedTime,
a.CustID,
a.CallType,
a.CallDesc,
(select TOP 1 HEATSeq from Asgnmnt f
WHERE a.CallID = f.CallID
ORDER BY HEATSeq desc) as HeatSeq#
FROM dbo.CallLog a
where a.CallID = '00520308') as z
LEFT OUTER JOIN dbo.Asgnmnt c on z.Callid=c.CallID and z.HeatSeq# = c.HEATSeq
Here is the [ERROR]
Msg 209, Level 16, State 1, Line 2
Ambiguous column name 'Callid'.
Msg 209, Level 16, State 1, Line 9
Ambiguous column name 'CallType'