Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
andy11983
Starting Member
3 Posts |
Posted - 2006-07-19 : 11:37:23
|
Hi guys i'm a newbie to this forums so hopefully i've posted in the right place, so here goes .....My company has been given a CMS to look at, thing is everything seems to be working except for this beasty stored procedure.. the purpose of this stored procedure is to gather data and output it as xml, but for some reason and i havent a clue why - i am getting an error stated below - i have also enclosed the stored procedured in hopes of some kind gururs can help me Appreciate any and all help guysMany thanks in advanceandyERRROR MESSAGE:Microsoft OLE DB Provider for SQL Server error '80040e21' Parent tag ID 1 is not among the open tags. FOR XML EXPLICIT requires parent tags to be opened first. Check the ordering of the result set. [b]STORED PROCEDURE/* * spxCMGetTreeXML - Initiates the XML which is used to render the main content management tree. * * DATE DEVELOPER CHANGE * 2004-03-11 DC Created * 2004-03-22 CB Added the check for @blnIsGlobalAdmin before calling ftnCMCheckUserPermits * 2004-03-24 DC Commented out above change. Now checking ftnCMCheckUserPermits at intance level as well. * 2004-03-26 DC Implemented IsSingleInstance on CMObjects * 2004-04-02 DC Implemented VersionNumber on CMVersions * 2004-04-03 DC Only offer delete option for instances with no live children * 2004-04-06 DC Now accepting and observing blnCompex * 2004-04-29 DC Now accepting and observing blnForDialog * 2005-02-22 AgMcC An instance with children can be deleted if all it's children have been deleted * 2005-10-31 AgMcC Added friendly url (furl) so it can be used on internal links * 2006.01.11 JS Added friendly url attribute for GoToLive */CREATE PROCEDURE spxCMGetTreeXML ( @intBrandID INT=NULL, @intAreaID INT=NULL, @intUserID INT=NULL, @blnComplex BIT, @blnForDialog BIT=0) ASDECLARE @blnIsGlobalAdmin BIT--last paramater overides 2nd lastIF @blnForDialog=1 BEGIN SET @blnComplex=0 SET @blnIsGlobalAdmin = 0 ENDELSE BEGIN --work out of this user gets god-mode privs (1 = global admin role ID) IF EXISTS ( SELECT * FROM SecurityUsers_SecurityRoles WHERE SecurityUsersID = @intUserID AND SecurityRolesID = 1 ) SET @blnIsGlobalAdmin = 1 END--declare variables / tables to store intermediate dataDECLARE @objObjects TABLE ( [ID] INT, [Description] NVARCHAR(128) COLLATE database_default, DescriptionPlural NVARCHAR(128) COLLATE database_default, CanAdd BIT, CanEdit BIT, CanDelete BIT, CanOverwrite BIT, CanView BIT, HasTemplate BIT, IsChild BIT, HasKids BIT, SingleInstance BIT, InstanceCount INT NULL)DECLARE @objInstances TABLE (InstanceID INT, ObjectID INT, [Name] NVARCHAR(128), StateID INT, WFStateID INT NULL, MightHaveKids BIT, ChildCount INT NULL)--work out which types of object for the given brand/area this user has any rights toINSERT INTO @objObjects ([ID], [Description], DescriptionPlural, CanAdd, CanEdit, CanDelete, CanOverwrite, CanView, HasTemplate, IsChild, HasKids, SingleInstance)SELECT DISTINCT o.[ID], o.[Description], o.DescriptionPlural, dbo.ftnCMCheckUserPermits(@intUserID, o.[ID], NULL, NULL, 1,0), dbo.ftnCMCheckUserPermits(@intUserID, o.[ID], NULL,NULL, 2,0), dbo.ftnCMCheckUserPermits(@intUserID, o.[ID], NULL, NULL, 3,0), dbo.ftnCMCheckUserPermits(@intUserID, o.[ID], NULL,NULL, 4,0), dbo.ftnCMCheckUserPermits(@intUserID, o.[ID], NULL,NULL, 6,0), CASE WHEN cmot.[ID] IS NULL THEN 0 ELSE 1 END, CASE WHEN cor.[ID] IS NULL THEN 0 ELSE 1 END, CASE WHEN cor2.[ID] IS NULL THEN 0 ELSE 1 END, o.IsSingleInstanceFROM CMObjects oLEFT JOIN CMObjectRelationships corON cor.TargetCMObjectID=o.[ID]AND cor.CMRelationshipTypeID=1LEFT JOIN CMObjectRelationships cor2ON cor2.CMObjectID=o.[ID]AND cor2.CMRelationshipTypeID=1LEFT OUTER JOIN CMObjectTemplates cmotON cmot.CMObjectID = o.[ID]WHERE (NavBrandsID=@intBrandID OR @intBrandID IS NULL)AND (NavSiteAreasID = @intAreaID OR @intAreaID IS NULL)--add all instances of objects which we have object-level permits toINSERT INTO @objInstances(InstanceID, ObjectID, [Name], StateID, WFStateID, MightHaveKids)SELECT i.[ID], i.CMObjectID, i.[Name], i.CMStateID, i.CMWorkflowStateID, o.HasKidsFROM @objObjects oJOIN CMInstances iON i.CMObjectID=o.[ID]WHERE (o.CanEdit=1 OR o.CanDelete=1 OR o.CanOverwrite=1 OR o.CanView = 1) AND (i.CMStateID<>5 OR @blnComplex=1) --no deleted instance in simple view, thanksORDER BY Name--add instances of objects which we dont have object-level permits to, if we have intance-level permitsINSERT INTO @objInstances(InstanceID, ObjectID, [Name], StateID, WFStateID, MightHaveKids)SELECT i.[ID], i.CMObjectID, i.[Name], i.CMStateID, i.CMWorkflowStateID, o.HasKidsFROM @objObjects oJOIN CMInstances iON i.CMObjectID=o.[ID]WHERE ((o.CanEdit=0 AND o.CanDelete=0 AND o.CanOverwrite=0 or o.CanView = 0) AND dbo.ftnCMCheckUserPermits(@intUserID, NULL, i.[ID],NULL, NULL,0)=1)AND (i.CMStateID<>5 OR @blnComplex=1) --no deleted instance in simple view, thanksORDER BY Name--get child count for those instances that might have kidsUPDATE @objInstances SET ChildCount=(SELECT COUNT(*) FROM CMInstances WHERE CMParentInstanceID = InstanceID AND CMStateID <> 5) WHERE MightHaveKids=1--get instance count for those object that might have instancesUPDATE @objObjects SET InstanceCount=(SELECT COUNT(*) FROM @objInstances WHERE ObjectID = [ID])IF @blnComplex=1 -- generate 'content' tree for everyone SELECT 1 AS tag, NULL AS parent, 'content' AS [node!1!id], 'Content' AS [node!1!description], 1 AS [node!1!isopen] FOR XML EXPLICITIF EXISTS (SELECT * FROM @objObjects WHERE SingleInstance=1) -- if there are any single-instance pages, a catch all top level item for them to be under SELECT 1 AS tag, NULL AS parent, 'individual' AS [node!1!id], 'Individual pages' AS [node!1!description], CASE @blnComplex WHEN 1 THEN 'content' ELSE NULL END AS [node!1!parentid], 0 AS [node!1!isopen] FOR XML EXPLICIT-- 1st OBJECT level data - where the object is not a child and you can add a new instance of it or there is already 1 or more instancesSELECT 1 AS tag, NULL AS parent, 'o' + CAST([ID] AS VARCHAR) AS [node!1!id], NULL AS [node!1!friendlyurl], DescriptionPlural AS [node!1!description], CASE @blnComplex WHEN 1 THEN 'content' ELSE NULL END AS [node!1!parentid], NULL AS [node!1!subtitle], 0 AS [node!1!isopen], DescriptionPlural AS [node!1!sortorder], HasTemplate AS [node!1!hastemplate], 1 AS [node!1!step], NULL AS [command!2!id], NULL AS [command!2!description]FROM @objObjectsWHERE (IsChild=0 AND SingleInstance=0)AND (CanAdd=1 OR CanEdit=1 OR CanDelete= 1 OR CanOverwrite = 1 OR CanView = 1 OR InstanceCount > 0) -- ########### CHANGE TO UNION ALL ??????? FROM UNION################# UNION ALL-- 2nd generate content nodes (instances)SELECT 1 AS tag, NULL AS parent, 'i' + CAST(i.[ID] AS VARCHAR) AS [node!1!id], cmvfurl.FriendlyURL AS [node!1!friendlyurl], i.[Name] AS [node!1!description], CASE WHEN i.CMParentInstanceID IS NULL AND ids.SingleInstance=0 THEN 'o' + CAST( i.CMObjectID AS VARCHAR) -- This object has more than one instance, therefore display the object WHEN i.CMParentInstanceID IS NULL AND ids.SingleInstance=1 THEN 'individual' -- This is the only instance of the object - so set it as top level WHEN i.CMParentInstanceID IS NOT NULL THEN 'i' + CAST(CMParentInstanceID AS VARCHAR) -- It's a child object, so nest under parent instance END AS [node!1!parentid], '(' + s.[Name] + COALESCE(' - ' + ws.[Name],'') + ')' AS [node!1!subtitle], 0 AS [node!1!isopen], i.[Name] AS [node!1!sortorder], HasTemplate AS [node!1!hastemplate], 2 AS [node!1!step], NULL AS [command!2!id], NULL AS [command!2!description]FROM @objInstances oiJOIN CMInstances iON oi.InstanceID = i.[ID]JOIN CMStates sON i.CMStateID = s.[ID] --AND s.Render=1LEFT JOIN CMWorkflowStates wsON i.CMWorkflowStateID = ws.[ID]JOIN @objObjects idsON ids.[ID] = i.CMObjectIDINNER JOIN CMVersions cmvON i.[ID] = cmv.CMInstanceIDAND CMVersionTypeID = 2LEFT OUTER JOIN CMVersionFriendlyURL cmvfurlON cmv.[ID] = cmvfurl.CMVersionIDUNION ALL-- 4th generate 'add new...' command for top-level objects, where possibleSELECT 2 AS tag, 1 AS parent, 'o' + CAST(i.[ID] AS VARCHAR) AS [node!1!id], NULL AS [node!1!friendlyurl], NULL AS [node!1!description], NULL AS [node!1!parentid], NULL AS [node!1!subtitle], NULL AS [node!1!isopen], NULL AS [node!1!sortorder], NULL AS [node!1!hastemplate], 4 AS [node!1!step], 'a' AS [command!2!id], 'Add New ' + [Description] + '...' AS [command!2!description]FROM @objObjects iWHERE i.CanAdd=1 AND i.IsChild=0 AND SingleInstance=0 AND @blnForDialog=0 UNION ALL-- 4.5th generate 'permissions...' command for top-level objects, where possibleSELECT 2 AS tag, 1 AS parent, 'o' + CAST(i.[ID] AS VARCHAR) AS [node!1!id], NULL AS [node!1!friendlyurl], NULL AS [node!1!description], NULL AS [node!1!parentid], NULL AS [node!1!subtitle], NULL AS [node!1!isopen], NULL AS [node!1!sortorder], NULL AS [node!1!hastemplate], 4.5 AS [node!1!step], 'p' AS [command!2!id], 'Permissions...' AS [command!2!description]FROM @objObjects iWHERE (IsChild=0 AND SingleInstance=0)AND @blnIsGlobalAdmin=1 AND @blnForDialog=0 AND @blnComplex=0 UNION ALL-- 5th generate 'add new...' command for instances, where possible. one for each instance of the object to which the chid object belongsSELECT 2 AS tag, 1 AS parent, 'i' + CAST(i.InstanceID AS VARCHAR) AS [node!1!id], NULL AS [node!1!friendlyurl], NULL AS [node!1!description], NULL AS [node!1!parentid], NULL AS [node!1!subtitle], NULL AS [node!1!isopen], NULL AS [node!1!sortorder], NULL AS [node!1!hastemplate], 5 AS [node!1!step], 'a' + CAST(o.[ID] AS VARCHAR) AS [command!2!id], 'Add New ' + o.[Description] + '...' AS [command!2!description]FROM @objInstances iJOIN @objObjects idsON ids.[ID] = i.ObjectID AND ids.HasKids=1JOIN CMObjectRelationships corON cor.CMObjectID=i.ObjectID AND cor.CMRelationshipTypeID=1JOIN @objObjects oON cor.TargetCMObjectID = o.[ID] AND o.CanAdd=1WHERE @blnForDialog=0 UNION ALL-- 6th generate 'edit...' command for instances, where possible.SELECT 2 AS tag, 1 AS parent, 'i' + CAST(i.InstanceID AS VARCHAR) AS [node!1!id], NULL AS [node!1!friendlyurl], NULL AS [node!1!description], NULL AS [node!1!parentid], NULL AS [node!1!subtitle], NULL AS [node!1!isopen], NULL AS [node!1!sortorder], NULL AS [node!1!hastemplate], 6 AS [node!1!step], 'e' AS [command!2!id], 'Edit...' AS [command!2!description]FROM @objObjects oJOIN @objInstances iON o.[ID] = i.ObjectIDWHERE (o.CanEdit=1 OR dbo.ftnCMCheckUserPermits(@intUserID, NULL, i.InstanceID, NULL, 2,0)=1)AND i.StateID=2 --(can only edit live instances) AND @blnForDialog=0 UNION ALL-- 7th generate 'delete...' command for instances, where possible.SELECT 2 AS tag, 1 AS parent, 'i' + CAST(i.InstanceID AS VARCHAR) AS [node!1!id], NULL AS [node!1!friendlyurl], NULL AS [node!1!description], NULL AS [node!1!parentid], NULL AS [node!1!subtitle], NULL AS [node!1!isopen], NULL AS [node!1!sortorder], NULL AS [node!1!hastemplate], 7 AS [node!1!step], 'd' AS [command!2!id], 'Delete...' AS [command!2!description]FROM @objObjects oJOIN @objInstances iON o.[ID] = i.ObjectIDWHERE (o.CanDelete=1 OR dbo.ftnCMCheckUserPermits(@intUserID, NULL, i.InstanceID,NULL, 3,0)=1)AND i.StateID=2 AND (i.ChildCount=0 OR i.ChildCount IS NULL) --(can only delete live instances with no kids)AND o.SingleInstance=0 --(cant delete single instance pages)AND @blnForDialog=0 UNION ALL-- 7.5th generate 'overwrite...' command for instances, where possible.SELECT 2 AS tag, 1 AS parent, 'i' + CAST(i.InstanceID AS VARCHAR) AS [node!1!id], NULL AS [node!1!friendlyurl], NULL AS [node!1!description], NULL AS [node!1!parentid], NULL AS [node!1!subtitle], NULL AS [node!1!isopen], NULL AS [node!1!sortorder], NULL AS [node!1!hastemplate], 7.5 AS [node!1!step], 'x' AS [command!2!id], 'Overwrite...' AS [command!2!description]FROM @objObjects o JOIN @objInstances iON o.[ID] = i.ObjectIDWHERE (o.CanOverwrite=1 OR dbo.ftnCMCheckUserPermits(@intUserID, NULL, i.InstanceID,NULL, 4,0)=1)AND (i.StateID = 1 OR i.StateID=3) --(can only overwrite new or changed instances)AND @blnForDialog=0 UNION ALL-- 7.75th generate 'overwrite...' command for instances, where possible.SELECT 2 AS tag, 1 AS parent, 'i' + CAST(i.InstanceID AS VARCHAR) AS [node!1!id], NULL AS [node!1!friendlyurl], NULL AS [node!1!description], NULL AS [node!1!parentid], NULL AS [node!1!subtitle], NULL AS [node!1!isopen], NULL AS [node!1!sortorder], NULL AS [node!1!hastemplate], 7.75 AS [node!1!step], 'h' AS [command!2!id], 'Show History...' AS [command!2!description]FROM @objInstances iWHERE @blnForDialog=0 UNION ALL-- 7.85th generate 'go to live page...' command for instances, where possible.SELECT 2 AS tag, 1 AS parent, 'i' + CAST(i.InstanceID AS VARCHAR) AS [node!1!id], NULL AS [node!1!friendlyurl], NULL AS [node!1!description], NULL AS [node!1!parentid], NULL AS [node!1!subtitle], NULL AS [node!1!isopen], NULL AS [node!1!sortorder], NULL AS [node!1!hastemplate], 7.85 AS [node!1!step], 'g' AS [command!2!id], 'Go to Live Page...' AS [command!2!description]FROM @objInstances i JOIN CMStates sON i.StateID = s.[ID]WHERE s.Render=1 AND @blnForDialog=0 UNION ALL-- 8th generate 'permissions...' command for instances, where possible.SELECT 2 AS tag, 1 AS parent, 'i' + CAST(i.InstanceID AS VARCHAR) AS [node!1!id], NULL AS [node!1!friendlyurl], NULL AS [node!1!description], NULL AS [node!1!parentid], NULL AS [node!1!subtitle], NULL AS [node!1!isopen], NULL AS [node!1!sortorder], NULL AS [node!1!hastemplate], 7.5 AS [node!1!step], 'p' AS [command!2!id], 'Permissions...' AS [command!2!description]FROM @objInstances iWHERE @blnIsGlobalAdmin=1 AND @blnForDialog=0ORDER BY [node!1!id], parent, tag, [node!1!parentid]FOR XML EXPLICITIF @blnComplex=1 BEGIN -- generate content "version" parent nodes SELECT DISTINCT 1 AS tag, NULL AS parent, 'iv' + CAST(i.InstanceID AS VARCHAR) AS [node!1!id], 'Versions' AS [node!1!description], 'i' + CAST(i.InstanceID AS VARCHAR) AS [node!1!parentid], NULL AS [node!1!subtitle], 1 AS [node!1!isopen], 2.5 AS [node!1!step], NULL AS [command!2!id], NULL AS [command!2!description] FROM CMVersions v JOIN @objInstances i ON v.CMInstanceID = i.InstanceID FOR XML EXPLICIT -- generate version nodes SELECT 1 AS tag, NULL AS parent, 'v' + CAST(v.[ID] AS VARCHAR) AS [node!1!id], CAST(v.VersionNumber AS VARCHAR) + '. ' + vt.[Name] AS [node!1!description], 'iv' + CAST(i.InstanceID AS VARCHAR) AS [node!1!parentid], '(' + dbo.ftnInfraFormatDateTime(v.LastEditDate) + ' - ' + su.FirstName + ' ' + su.LastName + ')' AS [node!1!subtitle], 0 AS [node!1!isopen], v.[ID] AS [node!1!sortme], NULL AS [command!2!id], NULL AS [command!2!description] FROM CMVersions v JOIN SecurityUsers su ON v.AuthorUserID = su.[ID] JOIN CMVersionTypes vt ON v.CMVersionTypeID = vt.[ID] JOIN @objInstances i ON v.CMInstanceID = i.InstanceID UNION -- generate "preview" command for version nodes SELECT 2 AS tag, 1 AS parent, 'v' + CAST(v.[ID] AS VARCHAR) AS [node!1!id], NULL AS [node!1!description], NULL AS [node!1!parentid], NULL AS [node!1!subtitle], NULL AS [node!1!isopen], v.[ID] AS [node!1!sortme], 'wp' AS [command!2!id], 'Show Page...' AS [command!2!description] FROM CMVersions v JOIN @objInstances i ON v.CMInstanceID = i.InstanceID UNION -- generate "show data" command for version nodes SELECT 2 AS tag, 1 AS parent, 'v' + CAST(v.[ID] AS VARCHAR) AS [node!1!id], NULL AS [node!1!description], NULL AS [node!1!parentid], NULL AS [node!1!subtitle], NULL AS [node!1!isopen], v.[ID] AS [node!1!sortme], 'wd' AS [command!2!id], 'Show Data...' AS [command!2!description] FROM CMVersions v JOIN @objInstances i ON v.CMInstanceID = i.InstanceID ORDER BY [node!1!sortme], tag ASC FOR XML EXPLICIT ENDIF @blnIsGlobalAdmin=1 AND @blnComplex=1 BEGIN -- generate 'permissions...' tree for global admins only. SELECT 1 AS tag, NULL AS parent, 'permits' AS [node!1!id], 'Object Permissions' AS [node!1!description], 0 AS [node!1!isopen] FOR XML EXPLICIT SELECT 1 AS tag, NULL AS parent, 'p' + CAST([ID] AS VARCHAR) AS [node!1!id], DescriptionPlural AS [node!1!description], 'permits' AS [node!1!parentid], NULL AS [node!1!subtitle], 1 AS [node!1!isopen], DescriptionPlural AS [node!1!sortorder] FROM @objObjects FOR XML EXPLICIT END GOb] |
|
|
andy11983
Starting Member
3 Posts |
Posted - 2006-07-20 : 04:16:36
|
hi again,i have figured out where the error message is coming from but cant understand why.the error is generated by that line, ORDER BY [node!1!id], parent, tag, [node!1!parentid]can anybody please helpcheersandy |
 |
|
|
|
|
|
|
|