• toniupstny (2/8/2008)


    Nice script.

    A couple of questions for you:

    - Shouldn't there be a set of [ ] around the variables in case they contain special characters like blanks or SQL keywords?

    - How can you handle special characters in the LIKE comparison if a string you would search for has a %, _, [ ], [^ ] or quotes?

    I agree. It failed immediately for me for a column named "Group".

    SET @Sql = 'SELECT @Row_Count = COUNT(*) '+

    ' FROM ' + @Table_Name + ' (NOLOCK) WHERE [' + @Column_Name + '] LIKE ''%' + @Search_For + '%'''

    Adding the brackets prevents the ambiguity of the word.

    Given that, I see this as a useful time-saver when a word or phrase may have been used in numerous places.

    Thanks!