Reputation: 21
I am quite new to SQL Server. I have an issue where we have a stored procedure called sys.sp_MSallocate_new_identity_range
(see part of logic below). It makes reference to two functions neither of which I can locate.
if (**sys.fn_MSmerge_isrepublisher**(@artid)=0)
begin
declare @publisher_max_used numeric(38,0)
declare @pubid uniqueidentifier
declare @pub_ranges_needed tinyint
declare @pub_refresh_constraint bit
select @pubid = subid, @publisher_max_used = max_used from dbo.MSmerge_identity_range
where artid = @artid and is_pub_range = 1 and (**sys.fn_MSmerge_islocalpubid**(subid)=1)
if @pubid is NULL
begin
raiserror(20663, 16, -1)
return 1
end
Running the stored prcoedure with appropriate parameters - returns a result :
declare @p4 smallint
set @p4=2
declare @p5 numeric(38,0)
set @p5=31001
declare @p6 numeric(38,0)
set @p6=32001
declare @p7 numeric(38,0)
set @p7=32001
declare @p8 numeric(38,0)
set @p8=33001
exec sys.sp_MSallocate_new_identity_range 'B551D87F-5457-2102-9E6A-DD4EB44B1DD1','4EB5E2D0-3FC1-4D77-B894-5D57C433D0B2',2,@p4 output,@p5 output,@p6 output,@p7 output,@p8 output,N'dev_02',N'PPC04 - 21a535007fd8',N'My Documents\Assets\assets.sdf'
select @p4, @p5, @p6, @p7, @p8
i.e This works and returns a result. All Good - but I cannot locate the functions embedded within the stored procedure i.e. sys.fn_MSmerge_isrepublisher
or sys.fn_MSmerge_islocalpubid
.
I have looked in sys.objects
and sys.all_objects where name like '%fn_MSmerge%'
.
I have managed to trace the SQL and the trace gives an ObjectID and I can see the statement executing. The trace tells me it is a function - 20038 - FN - and gives me an objectid of 563464549 - but cannot find by looking in sys.objects for the database
Any help/advice gladly accepted.
Upvotes: 2
Views: 262
Reputation: 453067
These object definitions do seem to be hidden. If you connect via the DAC and run
SELECT OBJECT_DEFINITION(OBJECT_ID('sys.fn_MSmerge_islocalpubid')) AS
[processing-instruction(x)],
OBJECT_DEFINITION(OBJECT_ID('sys.fn_MSmerge_isrepublisher')) AS
[processing-instruction(y)]
FOR XML PATH('')
you can see them though. The definitions for my version of SQL Server are as below
create function sys.fn_MSmerge_islocalpubid (@pubid uniqueidentifier)
returns bit
as
begin
declare @publisher_db sysname
declare @publisher sysname
select @publisher_db = publisher_db, @publisher = publisher
from dbo.sysmergepublications
where pubid = @pubid
if @publisher_db is NULL or @publisher is NULL
return 0
if @publisher_db = db_name() and UPPER(@publisher) = UPPER(publishingservername())
return 1
return 0
end
create function sys.fn_MSmerge_isrepublisher (@artid uniqueidentifier)
returns bit
as
begin
if exists (select pubid from dbo.sysmergearticles where artid = @artid and (sys.fn_MSmerge_islocalpubid(pubid) = 0))
return 1
return 0
end
Upvotes: 1