May 15, 2012

sp_MSget_publication_from_taskname (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_MSget_publication_from_taskname(nvarchar @taskname
, nvarchar @publisher
, nvarchar @publisherdb)

MetaData:

 create procedure sys.sp_MSget_publication_from_taskname  
@taskname sysname,
@publisher sysname,
@publisherdb sysname,
@publication sysname OUTPUT
as
declare @value sysname
declare @value2 sysname
declare @position INT

select @publication = NULL

-- Security check: sysadmin only
if (isnull(is_srvrolemember('sysadmin'),0) = 0)
begin
raiserror(21089,16,-1)
return 1
end

-- Parse out publication name from the task name "publisher_publisherdb_publication_number"
-- Expect publisher name
if charindex(@publisher, @taskname) <> 1
begin
return 1
end

-- Eat up the publisher name
select @value = stuff(@taskname, 1, len(@publisher), N'')

-- Expect '_' + publisherdb + '_'
select @value2 = N'_' + @publisherdb + N'_'
if charindex(@value2, @value) <> 1
begin
return 1
end

-- Eat up '_' + publisherdb + '_'
select @value = stuff(@value, 1, LEN(@publisherdb) + 2, N'')

-- Reverse the string in the hope of finding the first '_'
-- from the right which denotes the end of the publication
-- name. The number at the end should not contain '_'
select @value2 = reverse(@value)
select @position = charindex(N'_', @value2)
if @position < 2
begin
return 1
end

select @publication = left(@value, len(@value) - @position)
return 0

No comments:

Post a Comment

Total Pageviews