SELECT DISTINCT
a.AssetId, a.OriginalFileName, a.UserFileName, a.BCSNumber, a.Description, a.AssetStatusID, 
a.CreatedOn, a.CreatedByUserID, a.UpdatedOn, a.UpdatedByUserID, a.CopyClaimFileName
,c.AssetCategoryName
,ai.AssetItemName
,f.FocusItemID
,fi.FocusItemName
,img.OriginalSize
,a.publishDate
,a.archiveDate
,y.AssetCampaignYearName
,p.ProjectName
,a.isConfidential
,u.FirstName
,u.LastName
,u.CompanyName
,ff.FulfillmentCompanyName
,ast.AssetStatusName
,aty.AssetTypeName
,org.OrganizationName
,rel.ReleaseID
,rel.ReleaseName
,rel.ReleaseTypeID
,rel.ReleaseStatusID
,rel.Licensor
,rel.CreatedDate
,rel.FileName
,rel.FilePath


FROM Assets a
LEFT JOIN AssetCategories c ON a.AssetCategoryID = c.AssetCategoryID
LEFT JOIN AssetItems ai ON a.AssetItemID = ai.AssetItemID
LEFT JOIN AssetFocusItemMap f ON a.AssetId = f.AssetID
LEFT JOIN FocusItems fi ON f.FocusItemID = fi.FocusItemID
LEFT JOIN AssetImages img ON a.AssetID = img.AssetID
LEFT JOIN AssetCampaignYears y ON a.AssetCampaignYearID = y.AssetCampaignYearID
LEFT JOIN Projects p ON a.ProjectID = p.ProjectID
LEFT JOIN Users u ON a.CreatedByUserID = u.UserID
LEFT JOIN FulfillmentCompanies ff ON a.FulfillmentCompanyID = ff.FulfillmentCompanyID
LEFT JOIN AssetStatuses ast ON a.AssetStatusID = ast.AssetStatusID
LEFT JOIN AssetTypes aty ON a.AssetTypeID = aty.AssetTypeID


-- all these joins only to get the "Available to" matrix
LEFT JOIN AssetGroupSecurityFunctionMap agsfm ON a.AssetID = agsfm.AssetID
LEFT JOIN Organizations org ON org.OrganizationID = agsfm.OrganizationID
LEFT JOIN Groups grp ON grp.GroupID = agsfm.GroupID
--LEFT JOIN SecurityFunctions sf ON sf.SecurityFunctionID = agsfm.SecurityFunctionID
LEFT JOIN AssetRelease arel ON a.AssetID = arel.AssetID
LEFT JOIN Release rel ON arel.ReleaseID =  rel.ReleaseID


WHERE 
a.AssetStatusID != 101
AND a.CreatedOn > Convert(datetime, '2012-07-01')
AND a.isDeleted = 0
AND (a.FocusID IS NULL OR a.FocusID != 3 OR (a.FocusID = 3 AND a.CreatedOn > Convert(datetime, '2016-01-01')))
AND grp.GroupName != 'Administrator'


/*
AND a.AssetID IN (24024,24014,24007,23933,23932,23830,23826,23805,23804,
23803,23802,23801,23800,23799,23797,23751,23707,23688,23657,23629,23622,
23517,23484,23483,23472,23470,23467,23411,23392,23381,23211,22868,22488,
22481,22440,22082,22021,21147,20731,19557,19048,18447,18446,18445,18444,
16853,16171,15882,15313,14918,14400,13660,13641,13348,13323,13142,13135,
12844,12814,12007)
*/
