January 2022 Entries

  • Search through all tables for a string

    Occasionally it becomes important to find all rows that have a particular string – for example your shop address that is changing. https://www.mssqltips.com/sqlservertip/6148/sql-server-loop-through-table-rows-without-cursor/ Here I found a stored procedure, that given a table name will output all string columns+rows that contain a string.  In case it disappears, here is the complete code: USE master GO CREATE PROCEDURE dbo.sp_FindStringInTable @stringToFind VARCHAR(max), @schema sysname, @table sysname AS SET NOCOUNT ON BEGIN TRY DECLARE @sqlCommand varchar(max) = 'SELECT * FROM [' + @schema + '].[' + @table + '] WHERE ' SELECT...