The sql code is as follows:

SELECT @strXml = '<AccessRights projectId="'+CAST(@ProjectID AS VARCHAR(100))+'" userId="'+CAST(@UserID AS VARCHAR(100))+'">'    
SELECT @strXml = @strXml+'<object Id="' +  CAST(scr.objectCode as varchar(100))    
 + '" value="' +     
CASE WHEN AccessRight = 1 THEN  'N'        
WHEN AccessRight = 2 then 'V'        
WHEN AccessRight = 3 then 'F'        
FROM #screens scr left join #access acc 
ON acc.objectCode = scr.objectCode
SELECT @strXml = @strXml+'</AccessRights>'    

SELECT @strXml AS ResultSet
An error occurred while executing batch. Error message is: Invalid calling sequence: file stream must be initialized first.