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
,relUsr.FirstName
,relUsr.LastName
,relUsr.CompanyName
-- PhotoGallery:
,a.StateID
,sta.StateName
,a.GeographicInformation
,kelem.KeyElementName
,cgr.CropGroupName
,cfi.CropFieldName
,crop.CropName
,acrm.CropStage
,pety.PestTypeName
,pmap.Pest
,evty.EventTypeName
,aeve.Event
,a.NameOfPerson
,a.FamilyID

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
LEFT JOIN States sta ON a.StateID = sta.StateID
LEFT JOIN AssetKeyElementMap akem ON a.AssetID = akem.AssetID
LEFT JOIN KeyElement kelem ON akem.KeyElementID = kelem.KeyElementID
LEFT JOIN CropGroups cgr ON a.CropGroupID = cgr.CropGroupID
LEFT JOIN CropFields cfi ON a.CropFieldID = cfi.CropFieldID
LEFT JOIN AssetCropMap acrm ON a.AssetID = acrm.AssetID
LEFT JOIN Crop crop ON acrm.CropID = crop.CropID
LEFT JOIN AssetPetsMap pmap ON a.AssetID = pmap.AssetID
LEFT JOIN PestType pety ON pmap.PestTypeID = pety.PestTypeID
LEFT JOIN AssetEventMap aeve ON a.AssetID = aeve.AssetID
LEFT JOIN EventType evty ON aeve.EventTypeID = evty.EventTypeID


-- 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
LEFT JOIN Users relUsr ON rel.CreatedByUserID = relUsr.UserID


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'

-- Photo Gallery
AND a.FamilyID = 3

-- Logos & Brand Tags
--AND (a.AssetItemID = 46 OR a.AssetItemID = 67)


--AND a.AssetID = 5531