select attrTypeId from tbl_ORG_AttributeTypes with (nolock) where fsl_tableName = 'tbl_WRK_Emails' and fsl_tablecode = 'EML' and uniqueId = 'emailId' select attrTypeId from tbl_ORG_AttributeTypes with (nolock) where fsl_tableName = 'tbl_SYS_SavedReports' and fsl_tablecode = 'SRP' and uniqueId = 'savedReportId' select urr.reportRequestId, urr.savedReportId, urr.reportDate, urr.reportName, urr.referenceName, urr.reportMethod, urr.status, urr.downloadFile, urr.pdfPageCount, case when urr.reportMethod = 'EMAIL' and eml.emailId > 0 then cast( eml.emailId as bigint ) else null end as emailId, case when urr.reportMethod = 'EMAIL' and eml.emailId > 0 then cast( floor( 10191817 * sqrt( eml.emailId * log10( eml.emailId ))) as bigint ) else null end as emailTk from tbl_SYS_UserReportRequests urr with (nolock) left outer join tbl_ORG_AttributeLinks oal with (nolock) on oal.mstr_attrTypeId = and oal.child_attrTypeId = and oal.mstr_attrId = urr.savedReportId and 'EMAIL' = urr.reportMethod left outer join tbl_WRK_Emails eml with (nolock) on eml.ownerId = urr.ownerId and eml.ownerType = urr.ownerType and eml.emailId = cast( oal.child_attrId as bigint ) where urr.ownerId = and urr.ownerType = and urr.userId = and urr.deleted = 'N' order by urr.reportRequestId desc, urr.reportDate desc delete from tbl_SYS_SavedReports where savedReportId = and ownerId = and ownerType = and userId = and temporary = 'Y' delete from tbl_SYS_UserReportRequests where reportRequestId = and ownerId = and ownerType = and userId = select * from qmd_reportRequests where deleted = 'N' [ , { "reportRequestId" : #reportRequestId# , "#jsstringformat( _j )#" : null #_v# "#jsstringformat( _v )#" } ]