For those of you who are still on SQL 2005 and do not foresee an upgrade to SQL 2008, this could resolve some of your issues when synchronizing your profiles to your barcode scanner. SQL 2008 is different in how variables are declared therefore the code which was written for the barcode solution Post 7.1 SP 2 MP 1, will not work if your still on SQL 2005. The 2 statements I found which were missing from my database were the following:
spBarcodeGetProfileResourceCount
and
fnBarcodeSplitGuidSmall
I worked with Symantec to fix the first and they provided the attached code for it. On the second however, I was able to get the code working prior to hearing back from Symantec Support. It is also attached.
The issue with declaring the variables is in 2008, variables are declared as follows:
declare @xml XML = '<x><i>' + REPLACE(@Guids, ',', '</i><i>') + '</i></x>';
To modify it to work you have to Set the variable to something by using the SET function, causing the script to look like the following:
declare @xml XML
SET @XML =
'<x><i>' + REPLACE(@Guids, ',', '</i><i>') + '</i></x>';
Notice how the Declare and the Set lines are different from the Declare @xml XML=. Just a heads up for those beating your head against the desk, trying to figure out why this isn't working and waiting on an answer.
Here's the spBarcodeGetProfileResourceCount:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spBarcodeGetProfileResourceCount]
(
@TrusteeScope nvarchar(MAX),
@ProfileGuid uniqueidentifier = NULL,
@AssociationLevel int = 0,
@UserSpecifiedResources XML = NULL -- Data from UserSettings class
)
AS
BEGIN
-- Handle NULL Profile guid
IF (NULLIF(@ProfileGuid, '11111111-1111-1111-1111-111111111111') IS NULL)
BEGIN
SELECT 0;
RETURN; -- fast shortcut
END;
-- Directly load profile XML
DECLARE @profileXml as XML;
SELECT @profileXml = State FROM Item WHERE Guid = @ProfileGuid;
-- Cache selected associations
DECLARE @associations TABLE (Guid uniqueidentifier NOT NULL PRIMARY KEY CLUSTERED);
INSERT INTO @associations(Guid)
SELECT Guid.value('.', 'uniqueidentifier')
FROM @profileXml.nodes('/item/config/associations/association/text()') as Association(Guid);
-- Cache Resource Targets
DECLARE @targets TABLE (Ordinal int IDENTITY(0,1) NOT NULL, Guid uniqueidentifier NOT NULL);
INSERT INTO @targets (Guid)
SELECT ResourceTarget.Guid
FROM ResourceTarget
INNER JOIN @profileXml.nodes('/item/config/resourceTargets/target/text()') as SelectedResourceTarget(Guid) ON ResourceTarget.Guid = SelectedResourceTarget.Guid.value('.', 'uniqueidentifier');
-- Refresh Resource Targets (default to on)
IF NOT EXISTS (SELECT 1 FROM @profileXml.nodes('/item/config/AutoUpdateResourceTargets[text()="False"]/text()') as Condition(Value))
BEGIN
-- Refresh Resource Targets
DECLARE @targetIndex INT, @targetCount INT, @targetGuid UNIQUEIDENTIFIER;
SET @targetIndex = 0;
SELECT @targetCount = COUNT(*) FROM @targets;
WHILE (@targetIndex < @targetCount)
BEGIN
SELECT @targetGuid = Guid FROM @targets WHERE Ordinal = @targetIndex;
EXEC spResolveResourceTarget @resourceTargetGuid=@targetGuid, @forceRefresh=1, @runSilent=1;
SET @targetIndex = @targetIndex + 1;
END;
END;
-- CTE Version
WITH AssociatedResources_CTE(ResourceGuid, Level) AS
(
-- Anchor member definition
SELECT Guid, 0 as Level
FROM (
-- Include Asset Status resources
SELECT _ResourceGuid as Guid
FROM vFixedAssetStatus
UNION
-- Include Selected Specific Resources
SELECT ResourceGuid
FROM (
SELECT Guid.value('.', 'uniqueidentifier') as Guid FROM @profileXml.nodes('/item/config/users/user/text()') as [User](Guid)
UNION ALL
SELECT Guid.value('.', 'uniqueidentifier') as Guid FROM @profileXml.nodes('/item/config/departments/department/text()') as Department(Guid)
UNION ALL
SELECT Guid.value('.', 'uniqueidentifier') as Guid FROM @profileXml.nodes('/item/config/costcenters/costcenter/text()') as CostCenter(Guid)
UNION ALL
SELECT Guid.value('.', 'uniqueidentifier') as Guid FROM @profileXml.nodes('/item/config/locations/location/text()') as Location(Guid)
UNION ALL
SELECT Guid.value('.', 'uniqueidentifier') as Guid FROM @profileXml.nodes('/item/config/purchaseorders/purchaseorder/text()') as PurchaseOrder(Guid)
UNION ALL
SELECT Guid.value('.', 'uniqueidentifier') as Guid FROM @profileXml.nodes('/item/config/invoices/invoice/text()') as Invoice(Guid)
UNION ALL
SELECT Guid.value('.', 'uniqueidentifier') as Guid FROM @profileXml.nodes('/item/config/stockrooms/stockroom/text()') as StockRoom(Guid)
) as PickerResource
INNER JOIN ScopeMembership sm ON sm.ResourceGuid = PickerResource.Guid
INNER JOIN dbo.fnGetTrusteeScopeCollections(@TrusteeScope) as tsc on sm.ScopeCollectionGuid = tsc.ScopeCollectionGuid
UNION
-- Include Target Resources (Code Pulled from proc: spGetResourceTargetsMembershipScoped)
SELECT rtmc.ResourceGuid
FROM @targets ResourceTarget
INNER JOIN ResourceTargetMembershipCache rtmc ON rtmc.ResourceTargetGuid = ResourceTarget.Guid
INNER JOIN ScopeMembership sm ON rtmc.ResourceGuid = sm.ResourceGuid
INNER JOIN dbo.fnGetTrusteeScopeCollections(@TrusteeScope) as tsc on sm.ScopeCollectionGuid = tsc.ScopeCollectionGuid
UNION
-- Include User Specified Additional Resources
SELECT ResourceGuid
FROM @UserSpecifiedResources.nodes('/profile/resource/text()') as UserSpecifiedResource(Guid)
INNER JOIN ScopeMembership sm ON sm.ResourceGuid = UserSpecifiedResource.Guid.value('.', 'uniqueidentifier')
INNER JOIN dbo.fnGetTrusteeScopeCollections(@TrusteeScope) as tsc on sm.ScopeCollectionGuid = tsc.ScopeCollectionGuid
) as ProfileResources
UNION ALL
-- Recursive member definition
SELECT RA.ChildResourceGuid as ResourceGuid, AR.Level + 1
FROM ResourceAssociation as RA
INNER JOIN @associations A on (A.Guid = RA.ResourceAssociationTypeGuid)
INNER JOIN AssociatedResources_CTE as AR on (AR.ResourceGuid = RA.ParentResourceGuid)
INNER JOIN ScopeMembership sm ON RA.ChildResourceGuid = sm.ResourceGuid
INNER JOIN dbo.fnGetTrusteeScopeCollections(@TrusteeScope) as tsc on sm.ScopeCollectionGuid = tsc.ScopeCollectionGuid
WHERE AR.Level < @AssociationLevel
)
SELECT COUNT(DISTINCT Profile.ResourceGuid)
FROM AssociatedResources_CTE as Profile;
END;
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
AND here's the fnBarcodeSplitGuidSmall script:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[fnBarcodeSplitGuidsSmall]
(
@Guids nvarchar(max) -- Strict Format (EBNF): "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ("," "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")*
)
RETURNS @t TABLE (Ordinal int, Guid uniqueidentifier) WITH SCHEMABINDING as
BEGIN
-- Faster XML Algorithm --
declare @xml XML
SET @XML =
'<x><i>' + REPLACE(@Guids, ',', '</i><i>') + '</i></x>';
insert into @t (Ordinal, Guid)
select ROW_NUMBER() over (order by (select null)), Node.value('.', 'uniqueidentifier')
from @xml.nodes('/*/*/text()') as Item(Node);
return;
END;
GO