Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...Did anyone write a query to look for a specific string in all DNN tables?Did anyone write a query to look for a specific string in all DNN tables?
Previous
 
Next
New Post
11/24/2016 10:52 AM
 

Hello, the second one you gave me works better. 

I can clearly see the table names and the field names and the results show all the cells that DO contain the required string

Unfortunately there are 21893 occurrences... so my only choice is to trash the backup and hopefully find a way to downgrade a SLQ 2014 DB to be 2008 R2 compatible or at the very least 2012 compatible.

 

 
New Post
11/24/2016 7:46 PM
 
you might try modifying just database compatibility level in database options.

Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
 
New Post
11/25/2016 5:26 AM
 

Edoardo,

what about this?

DECLARE @sqlCmd nvarchar(max) = ''

DECLARE @badString nvarchar(max) = 'string to search for'
DECLARE @goodString nvarchar(max) = 'string to replace'

CREATE TABLE #TempCommands
(
   [Command] nvarchar(max)
)

SET NOCOUNT ON

;WITH cteTablesAndColumns (tableName, columnName)
AS
(
   SELECT DISTINCT
      t.name AS tableName,
      c.name AS columnName

   FROM
      sys.tables t
      INNER JOIN sys.columns c ON c.object_id = OBJECT_ID(t.name)
      INNER JOIN sys.types ty ON c.system_type_id = ty.system_type_id
   WHERE
      ty.name = 'nvarchar' OR ty.name = 'ntext'
)
INSERT INTO #TempCommands([Command])
SELECT '
   IF EXISTS(SELECT 1 FROM [' + tableName + '] WHERE [' + columnName + '] LIKE ''%' + @badString + '%'')
   BEGIN
      UPDATE [' + tableName + '] SET [' + columnName + '] = REPLACE([' + columnName + '], ''' + @badString + ''', ''' + @goodString + ''') WHERE [' + columnName + '] LIKE ''%' + @badString + '%''
   END
   GO
'
FROM cteTablesAndColumns

DECLARE curCommands CURSOR FOR SELECT [Command] FROM #TempCommands
OPEN curCommands
FETCH NEXT FROM curCommands INTO @sqlCmd
WHILE @@FETCH_STATUS = 0
BEGIN
   PRINT @sqlCmd
   FETCH NEXT FROM curCommands INTO @sqlCmd
END
CLOSE curCommands
DEALLOCATE curCommands
DROP TABLE #TempCommands

This should generate a SQL script that replaces the "bad string" with a "good string" (which can be empty, if you want). The update command is only executed if the string exists in that column/record.

Happy DNNing!
Michael


Michael Tobisch
DNN★MVP

dnn-Connect.org - The most vibrant community around the DNN-platform
 
New Post
11/25/2016 11:12 AM
 

Well :)

This sure is helpful!

I'll give it a try and see if I manage to clean up the whole thing

Thanks a lot Michael

 
New Post
11/25/2016 11:48 AM
 

Nope... unfortunately it does not seem to change the strings in the DB. 

It seems to do so but the truth is they are still there when I search for them.

Unless I did something wrong. Can I simply run this in a query window or do I have to create a stored procedure and run it?

 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...Did anyone write a query to look for a specific string in all DNN tables?Did anyone write a query to look for a specific string in all DNN tables?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out