|
Jayeff_land
Starting Member
2 Posts |
Posted - 2008-04-03 : 08:34:58
|
| Hi, I am working on a SQL Server query that is generating a XML fileformat (with For XML EXPLICIT) and I am getting an error in the SQLServer error when a executing the string with sp_executesql.The Error is:The Message is : Msg 6833.Parent tag ID 2 is not among the open tags. FOR XML EXPLICIT requiresparent tags to be opened first. Check the ordering of the result set.I have read a lot about the error on the forum except that I thinkthat in my case it is a little bit different cause the query returnthe exact xml file but cannot execute the same string with the Executecommand.When I am running the a copy of the query in a @str variable andexecuting with 'execute sp_executesql @str' command or only withExcute @str I am getting the error.But...When printing the string with print @str and executing (buttonexecute) the string within the query analyser it is working.Here is my SQL query :select1 as tag,NULL as parent,ID_metric as [lvl1!1!ID_metric],lineage as [lvl1!1!lineage],sort as [lvl1!1!sort],NULL as [lvl2!2!ID_metric],NULL as [lvl2!2!lineage],sort as [lvl2!2!sort],NULL as [lvl3!3!ID_metric],NULL as [lvl3!3!lineage],sort as [lvl3!3!sort]from#buildDatat1wheredbo.fn_countPatternInString('.',lineage)+1 = 1union allselect2 as tag,1 as parent,NULL as [lvl1!1!ID_metric],NULL as [lvl1!1!lineage],sort as [lvl1!1!sort],ID_metric as [lvl2!2!ID_metric],lineage as [lvl2!2!lineage],sort as [lvl2!2!sort],NULL as [lvl3!3!ID_metric],NULL as [lvl3!3!lineage],sort as [lvl3!3!sort]from#buildData t2wheredbo.fn_countPatternInString('.',lineage)+1 = 2union allselect3 as tag,2 as parent,NULL as [lvl1!1!ID_metric],NULL as [lvl1!1!lineage],sort as [lvl1!1!sort],NULL as [lvl2!2!ID_metric],NULL as [lvl2!2!lineage],sort as [lvl2!2!sort],ID_metric as [lvl3!3!ID_metric],lineage as [lvl3!3!lineage],sort as [lvl3!3!sort]from#buildData t3wheredbo.fn_countPatternInString('.',lineage)+1 = 3order by[lvl1!1!sort],[lvl2!2!sort],[lvl3!3!sort]for XML explicitFor your information : buildData is a temporary table andfn_countPatternInString is a function that is parsing a lineage to getdepht of the tree.Anybody have an a clue about this isssue? Tx |
|