I am using DNN Platform and I need help with an SQL query I am trying to run using the DNN SQL Console.
I need to change a small block of code that is used in several locations throughout the website. So I am trying to write an SQL query that searches the htmltext table for modules that still contain the block of code in the content field as I have changes it in a few locations already. Here is the query
Select moduleid from htmltext where content like 'codeblock'
The problem is that the table htmltext keeps the historical versions of the module. So if I already changed it in module 600 and module 600 has 5 total versions (versions 1-5) it will show module 600 4 times (version 1-4). None of these are the current version (version 5) of the module though.
So I need to change the query to only search the latest version of the modules in the htmltext table.
Anyone know how to change the query to accomplish this?
Select T.moduleID FROM HTMLText T JOIN (SELECT ModuleID, max(versionID) as latestVersion FROM HTMLText GROUP BY ModuleID) AS S ON T.ModuleID = S.ModuleID AND T.Version = S.Version WHERE T.content like 'codeblock'
In addition to Sebastian (and correcting one or two typos in his script): If you use the SQL Console in DNN, you might need the "DNN-SQL-Syntax", which is then:
SELECT T.ModuleID FROM {databaseOwner}{objectQualifier}HtmlText T INNER JOIN (SELECT ModuleID, MAX([Version]) as LatestVersion FROM {databaseOwner}{objectQualifier}HtmlText GROUP BY ModuleID) AS S ON T.ModuleID = S.ModuleID AND T.Version = S.LatestVersion WHERE T.Content LIKE '%codeblock%'
Please keep in mind that the content is stored HTML-encoded - so replace < by <, > by >, " by " etc.
Happy DNNing! Michael
Great thanks for the help. Worked great.
These Forums are dedicated to the discussion of DNN Platform.
For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:
Awesome! Simply post in the forums using the link below and we'll get you started.