select t2.UserName, t4.recordId from (select TSLocation.lcName as UserName, t1.ckdCnt as OffCnt, t1.OffDocUri as OffDocUri from TSLOCATION right join
(select reNameUri, uri as OffDocUri, COUNT(renameuri) as ckdCnt from TSRECELEC where reNameUri <> 0 and ltrim(rtrim(reCheckedOutOn)) <> '' and ltrim(rtrim(reCheckOutPath)) <> '' and reCheckOutType <> 0 group by reNameUri, uri )
AS t1 on TSLOCATION.uri = t1.reNameUri ) as t2 left join TSRECORD as t4 on t4.uri = t2.OffDocUri group by t2.UserName, t4.recordId
The query fails on AS keyword on the last line of the very first column.