Mitchel Stuart Fountaine Mitchel Stuart Fountaine - 3 months ago 9
SQL Question

Multi-Part Identifier could not be bound - Moving colum and data to different table

SELECT Contract as CaseRef, DateTime, Username
INTO #tempDB
FROM callhandlinginfo

INSERT INTO CallHandlingInfo(Event)
SELECT(Event)
FROM tblComplianceData
WHERE tblComplianceData.CaseRef = #tempdb.CaseRef

SELECT * FROM CallHandlingInfo


I get error


Multi-Part Identifier could not be bound.


Thanks all for the response, I see my mistake! What would it look like if it were an UPDATE Statement instead?

Answer

My best guess on what you want to accomplish is:

INSERT INTO CallHandlingInfo(Event)
    SELECT Event
    FROM tblComplianceData cd
    WHERE cd.CaseRef IN (SELECT cr.CaseRef FROM #tempdb.CaseRef cr);

You might want an update. Assuming SQL Server, it might look like this:

update chi
    set event = cd.event
    from callhandlinginfo chi join
         tblComplianceData cd
         on cd.CaseRef = chi.CaseRef;
Comments