Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSmodify_boolfilterclause

  No additional text.


Syntax

create procedure sys.sp_MSmodify_boolfilterclause (@bool_filterclause nvarchar(4000), @bool_filterclause_modified nvarchar(4000) OUTPUT) as
begin

    declare @func sysname, @func_no_parens sysname, @func_no_parens_to_replace_with sysname, @index int, @ilooper int, @cur_char nvarchar(1),
            @found_left_paren bit, @remaining_string nvarchar(4000), @offset_of_remaining_string int, @msp_column nvarchar(400)

    -- Len function ignores trailing blanks, so let's remove all trailing (and leading) blanks.
    select @bool_filterclause = ltrim(rtrim(@bool_filterclause))

    -- The reason we order by len of function name in the following cursor is to eliminate problems due to one function name contained
    -- in another. For example, user_name() is contained within suser_name(). So processing suser_name() before user_name() is important.
    declare functions_used CURSOR LOCAL FAST_FORWARD FOR
    select function_name_with_parens, function_name_without_parens
    from #list_of_functions
    order by len(function_name_with_parens) desc
    FOR READ ONLY

    open functions_used
    fetch next from functions_used into @func, @func_no_parens_to_replace_with

    while (@@fetch_status <> -1)
    begin

        select @func_no_parens = substring (@func, 1, len(@func)-2)
        select @msp_column = 'msp.' + quotename(ltrim(rtrim(@func_no_parens_to_replace_with)) + '_FN') + ' '

        if exists (select * from sys.columns
					where object_id = object_id('dbo.MSmerge_partition_groups')
					and name = quotename(ltrim(rtrim(@func_no_parens)) + '_FN')
					and type_name(user_type_id) in ('char', 'varchar', 'nchar', 'nvarchar'))
		begin
			select @msp_column = @msp_column + 'collate ' + convert(nvarchar(100),databasepropertyex(db_name(), N'COLLATION')) + ' '
		end

        select @remaining_string = @bool_filterclause
        select @offset_of_remaining_string = 1
        select @index = charindex (@func_no_parens collate SQL_Latin1_General_CP1_CI_AS,
                                            @remaining_string collate SQL_Latin1_General_CP1_CI_AS)

        while (@index <> 0)
        begin

            -- Make sure that this pattern match is indeed a function call. Look for the opening and closing
            -- parentheses. Note that there could be white space characters after the end of the function name
            -- and before the closing parenthesis.
            select @ilooper = @index + len(@func_no_parens)

            select @found_left_paren = 0

            while (@ilooper <= len(@remaining_string))
            begin
                select @cur_char = substring (@remaining_string, @ilooper, 1)
                if @cur_char = char(0x20) or @cur_char = char(0x09) or @cur_char = char(0x0D) or @cur_char = char(0x0A)
                begin
                    select @ilooper = @ilooper + 1
                    continue
                end

                else if @cur_char = '(' and @found_left_paren = 0
                begin
                    select @found_left_paren = 1
                    select @ilooper = @ilooper + 1
                    continue
                end

                else if @cur_char = ')' and @found_left_paren = 1
                begin
                    -- The following lines of code are hairier than they look. Please make sure you know what you are doing
                    -- before modifying them.
                    select @bool_filterclause = stuff(@bool_filterclause, @offset_of_remaining_string + @index -1, @ilooper - @index + 1, @msp_column)
                    select @offset_of_remaining_string = @offset_of_remaining_string + @index-1 + len(@msp_column)
                    select @remaining_string = right (@bool_filterclause, len(@bool_filterclause) - (@offset_of_remaining_string - 1))
                    select @index = charindex (@func_no_parens collate SQL_Latin1_General_CP1_CI_AS,
                                                        @remaining_string collate SQL_Latin1_General_CP1_CI_AS)
                    break
                end
                else
                begin
                    select @offset_of_remaining_string = @offset_of_remaining_string + @ilooper-1
                    -- we have run into something that indicates that this pattern is not a function invocation. skip it, and look for the next one
                    select @remaining_string = right (@bool_filterclause, len(@bool_filterclause)-(@offset_of_remaining_string - 1))
                    select @index = charindex (@func_no_parens collate SQL_Latin1_General_CP1_CI_AS,
                                                        @remaining_string collate SQL_Latin1_General_CP1_CI_AS)
                    break
                end
            end -- on to the next character in search of our opening and closing parenthesis after a pattern match
        end -- look for more occurrences of this function in the filter clause
    fetch next from functions_used into @func, @func_no_parens_to_replace_with
    end -- next function name from cursor

    select @bool_filterclause_modified = ' (' + @bool_filterclause + ') '

    close functions_used
    deallocate functions_used

    return 0

end -- end of proc

 
Last revision 2008RTM
See also

  sp_MSdrop_rladmin (Procedure)
sp_MSpublicationview (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash