select tcontent.contentid,tcontent.contenthistid,tcontent.siteid,tcontent.title,tcontent.menutitle,tcontent.targetParams,tcontent.filename,tcontent.summary,tcontent.tags, tcontent.restricted,tcontent.releaseDate,tcontent.type,tcontent.subType, tcontent.restrictgroups,tcontent.target ,tcontent.displaystart,tcontent.displaystop,0 as Comments, tcontent.credits, tcontent.remoteSource, tcontent.remoteSourceURL, tcontent.remoteURL,tfiles.fileSize,tfiles.fileExt,tcontent.fileID,tcontent.audience,tcontent.keyPoints, tcontentstats.rating,tcontentstats.totalVotes,tcontentstats.downVotes,tcontentstats.upVotes, 0 as kids, tparent.type parentType,tcontent.nextn,tcontent.path,tcontent.orderno,tcontent.lastupdate,tcontent.created, tcontent.created sortdate, 0 sortpriority from tcontent Left Join tfiles ON (tcontent.fileID=tfiles.fileID) Left Join tcontent tparent on (tcontent.parentid=tparent.contentid and tcontent.siteid=tparent.siteid and tparent.active=1) Left Join tcontentstats on (tcontent.contentid=tcontentstats.contentid and tcontent.siteid=tcontentstats.siteid) Inner Join tcontenttags on (tcontent.contentHistID=tcontenttags.contentHistID) where (tcontent.Active = 1 AND tcontent.Approved = 1 AND tcontent.siteid = ) AND ( tcontent.Display = 2 AND ( (tcontent.DisplayStart <= #createodbcdate(now())# AND (tcontent.DisplayStop >= #createodbcdate(now())# or tcontent.DisplayStop is null) ) OR tparent.type='Calendar' ) OR tcontent.Display = 1 ) AND tcontent.type in ('Page','Portal','Calendar','File','Link') AND tcontent.releaseDate is null and tcontent.path like and tcontenttags.Tag= and (UPPER(tcontent.Title) like or UPPER(tcontent.menuTitle) like or UPPER(tcontent.metaKeywords) like or UPPER(tcontent.summary) like or UPPER(tcontent.body) like ) and tcontent.searchExclude=0 and (tcontent.mobileExclude!=1 or tcontent.mobileExclude is null) union all select tcontent.contentid,tcontent.contenthistid,tcontent.siteid,tcontent.title,tcontent.menutitle,tcontent.targetParams,tcontent.filename,tcontent.summary,tcontent.tags, tcontent.restricted,tcontent.releaseDate,tcontent.type,tcontent.subType, tcontent.restrictgroups,tcontent.target ,tcontent.displaystart,tcontent.displaystop,0 as Comments, tcontent.credits, tcontent.remoteSource, tcontent.remoteSourceURL, tcontent.remoteURL,tfiles.fileSize,tfiles.fileExt,tcontent.fileID,tcontent.audience,tcontent.keyPoints, tcontentstats.rating,tcontentstats.totalVotes,tcontentstats.downVotes,tcontentstats.upVotes, 0 as kids, tparent.type parentType,tcontent.nextn,tcontent.path,tcontent.orderno,tcontent.lastupdate,tcontent.created, tcontent.releaseDate sortdate, 0 sortpriority from tcontent Left Join tfiles ON (tcontent.fileID=tfiles.fileID) Left Join tcontent tparent on (tcontent.parentid=tparent.contentid and tcontent.siteid=tparent.siteid and tparent.active=1) Left Join tcontentstats on (tcontent.contentid=tcontentstats.contentid and tcontent.siteid=tcontentstats.siteid) Inner Join tcontenttags on (tcontent.contentHistID=tcontenttags.contentHistID) where (tcontent.Active = 1 AND tcontent.Approved = 1 AND tcontent.siteid = ) AND ( tcontent.Display = 2 AND ( (tcontent.DisplayStart <= #createodbcdate(now())# AND (tcontent.DisplayStop >= #createodbcdate(now())# or tcontent.DisplayStop is null) ) OR tparent.type='Calendar' ) OR tcontent.Display = 1 ) AND tcontent.type in ('Page','Portal','Calendar','File','Link') AND tcontent.releaseDate is not null and tcontent.path like and tcontenttags.Tag= and (UPPER(tcontent.Title) like or UPPER(tcontent.menuTitle) like or UPPER(tcontent.metaKeywords) like or UPPER(tcontent.summary) like or UPPER(tcontent.body) like ) and tcontent.searchExclude=0 and (tcontent.mobileExclude!=1 or tcontent.mobileExclude is null) union all select tcontent.contentid,tcontent.contenthistid,tcontent.siteid,tcontent.title,tcontent.menutitle,tcontent.targetParams,tcontent.filename,tcontent.summary,tcontent.tags, tcontent.restricted,tcontent.releaseDate,tcontent.type,tcontent.subType, tcontent.restrictgroups,tcontent.target ,tcontent.displaystart,tcontent.displaystop,0 as Comments, tcontent.credits, tcontent.remoteSource, tcontent.remoteSourceURL, tcontent.remoteURL,tfiles.fileSize,tfiles.fileExt,tcontent.fileID,tcontent.audience,tcontent.keyPoints, tcontentstats.rating,tcontentstats.totalVotes,tcontentstats.downVotes,tcontentstats.upVotes, 0 as kids, tparent.type parentType,tcontent.nextn,tcontent.path,tcontent.orderno,tcontent.lastupdate,tcontent.created, tcontent.created sortdate, 1 sortpriority from tcontent Left Join tfiles ON (tcontent.fileID=tfiles.fileID) Left Join tcontent tparent on (tcontent.parentid=tparent.contentid and tcontent.siteid=tparent.siteid and tparent.active=1) Left Join tcontentstats on (tcontent.contentid=tcontentstats.contentid and tcontent.siteid=tcontentstats.siteid) Inner Join tcontenttags on (tcontent.contentHistID=tcontenttags.contentHistID) where (tcontent.Active = 1 AND tcontent.Approved = 1 AND tcontent.siteid = ) AND ( tcontent.Display = 2 AND ( (tcontent.DisplayStart <= #createodbcdate(now())# AND (tcontent.DisplayStop >= #createodbcdate(now())# or tcontent.DisplayStop is null) ) OR tparent.type='Calendar' ) OR tcontent.Display = 1 ) AND tcontent.type in ('Page','Portal','Calendar','File','Link') AND tcontent.releaseDate is null and tcontent.path like and tcontenttags.Tag= and not (UPPER(tcontent.Title) like or UPPER(tcontent.menuTitle) like or UPPER(tcontent.metaKeywords) like or UPPER(tcontent.summary) like or UPPER(tcontent.body) like ) and (UPPER(tcontent.Title) like or UPPER(tcontent.menuTitle) like or UPPER(tcontent.metaKeywords) like or UPPER(tcontent.summary) like or UPPER(tcontent.body) like ) and tcontent.searchExclude=0 and (tcontent.mobileExclude!=1 or tcontent.mobileExclude is null) union all select tcontent.contentid,tcontent.contenthistid,tcontent.siteid,tcontent.title,tcontent.menutitle,tcontent.targetParams,tcontent.filename,tcontent.summary,tcontent.tags, tcontent.restricted,tcontent.releaseDate,tcontent.type,tcontent.subType, tcontent.restrictgroups,tcontent.target ,tcontent.displaystart,tcontent.displaystop,0 as Comments, tcontent.credits, tcontent.remoteSource, tcontent.remoteSourceURL, tcontent.remoteURL,tfiles.fileSize,tfiles.fileExt,tcontent.fileID,tcontent.audience,tcontent.keyPoints, tcontentstats.rating,tcontentstats.totalVotes,tcontentstats.downVotes,tcontentstats.upVotes, 0 as kids, tparent.type parentType,tcontent.nextn,tcontent.path,tcontent.orderno,tcontent.lastupdate,tcontent.created, tcontent.releaseDate sortdate, 1 sortpriority from tcontent Left Join tfiles ON (tcontent.fileID=tfiles.fileID) Left Join tcontent tparent on (tcontent.parentid=tparent.contentid and tcontent.siteid=tparent.siteid and tparent.active=1) Left Join tcontentstats on (tcontent.contentid=tcontentstats.contentid and tcontent.siteid=tcontentstats.siteid) Inner Join tcontenttags on (tcontent.contentHistID=tcontenttags.contentHistID) where (tcontent.Active = 1 AND tcontent.Approved = 1 AND tcontent.siteid = ) AND ( tcontent.Display = 2 AND ( (tcontent.DisplayStart <= #createodbcdate(now())# AND (tcontent.DisplayStop >= #createodbcdate(now())# or tcontent.DisplayStop is null) ) OR tparent.type='Calendar' ) OR tcontent.Display = 1 ) AND tcontent.type in ('Page','Portal','Calendar','File','Link') AND tcontent.releaseDate is not null and tcontent.path like and tcontenttags.Tag= and not (UPPER(tcontent.Title) like or UPPER(tcontent.menuTitle) like or UPPER(tcontent.metaKeywords) like or UPPER(tcontent.summary) like or UPPER(tcontent.body) like ) and (UPPER(tcontent.Title) like or UPPER(tcontent.menuTitle) like or UPPER(tcontent.metaKeywords) like or UPPER(tcontent.summary) like or UPPER(tcontent.body) like ) and tcontent.searchExclude=0 and (tcontent.mobileExclude!=1 or tcontent.mobileExclude is null) select * from rs order by sortpriority, sortdate desc select tcontentcategoryassign.*, tcontentcategories.name from tcontentcategories inner join tcontentcategoryassign ON (tcontentcategories.categoryID=tcontentcategoryassign.categoryID) where tcontentcategoryassign.contentHistID= Order By tcontentcategories.name SELECT title, releasedate, menuTitle, lastupdate, summary, tcontent.filename, type, tcontent.contentid, target,targetParams, restricted, restrictgroups, displaystart, displaystop, orderno,sortBy,sortDirection, tcontent.fileid, credits, remoteSource, remoteSourceURL, remoteURL, tfiles.fileSize,tfiles.fileExt,path, tcontent.siteid, tcontent.contenthistid FROM tcontent Left Join tfiles ON (tcontent.fileID=tfiles.fileID) WHERE tcontent.siteid= and active=1 and tcontent.contentID in ( select relatedID from tcontentrelated where contentHistID= ) AND ( (tcontent.DisplayStart <= #createodbcdatetime(arguments.today)# AND (tcontent.DisplayStop >= #createodbcdatetime(arguments.today)# or tcontent.DisplayStop is null) AND tcontent.Display = 2) OR (tcontent.Display = 1) ) and (tcontent.mobileExclude!=1 or tcontent.mobileExclude is null) order by tcontent.created desc