Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FOR XML EXPLICIT, Error

Status
Not open for further replies.

aspnetvbnetnerd

Programmer
Feb 3, 2008
31
SE
I have a problem when creating an xml file.

It works when I remove the order by statement and it works when set it to for xml auto
If anyone could please help me with this I would personally fly my way to your country and give you a big hug. :)

I have been google and trying out a hundred different way's.
This has worked before.
Code:
SELECT
	1 			AS TAG, 
	NULL 			AS PARENT,
	FAKTURA.FAKTURAID	AS [FAKTURA!1!FAKTURAID],
	FAKTURA.RNR		AS [FAKTURA!1!RNR],
	FAKTURA.FackNr  	AS [FAKTURA!1!FACKNR], 
	FAKTURA.FakturaNummer 	AS [FAKTURA!1!FAKTURANUMMER], 
	FAKTURA.Bankgiro 	AS [FAKTURA!1!BANKGIRO], 
	FAKTURA.AbonnentNummer 	AS [FAKTURA!1!ABONNENTNUMMER],
	FAKTURA.FORBRUKNINGFROM AS [FAKTURA!1!FORBRUKNINGFROM],
	FAKTURA.FORBRUKNINGTOM 	AS [FAKTURA!1!FORBRUKNINGTOM],
	FAKTURA.FAKTURADATUM 	AS [FAKTURA!1!FAKTURADATUM],
	FAKTURA.POSTGIRO 	AS [FAKTURA!1!POSTGIRO],
	FAKTURA.ORGNUMMER 	AS [FAKTURA!1!ORGNUMMER],
	FAKTURA.MOMSREGNR 	AS [FAKTURA!1!MOMSREGNR],
	--FAKTURA.KREDIT 		AS [FAKTURA!1!KREDIT],
	FAKTURA.SAKRING 	AS [FAKTURA!1!SAKRING],
	FAKTURA.KVANTITET 	AS [FAKTURA!1!KVANTITET],
	ENHETER.ENHETSNAMN	AS [FAKTURA!1!ENHET],
	FAKTURA.ORESUTJAMNING 	AS [FAKTURA!1!ORESUTJAMNING],
	FAKTURA.GODKAND 	AS [FAKTURA!1!GODKAND],
	FAKTURA.SUMMABELOPP 	AS [FAKTURA!1!SUMMABELOPP],
	FAKTURA.MOMS 		AS [FAKTURA!1!MOMS],
	FAKTURA.KOMMENTAR 	AS [FAKTURA!1!KOMMENTAR],
	FAKTURA.SIDOR 		AS [FAKTURA!1!SIDOR],
	FAKTURA.BILD 		AS [FAKTURA!1!BILD],
	FAKTURA.readytoexport 	AS [FAKTURA!1!READYTOEXPORT],	
	NULL 			AS [FAKTURARAD!2!FAKTURAID!HIDE],
	NULL 			AS [FAKTURARAD!2!RADID!HIDE],
	NULL 			AS [FAKTURARAD!2!ARTIKELNAMN],
	NULL 			AS [FAKTURARAD!2!NOTERING],
	NULL 			AS [FAKTURARAD!2!KVANTITETRAD],
	NULL 			AS [FAKTURARAD!2!ENHET],
	NULL 			AS [FAKTURARAD!2!RADBELOPP],
	NULL 			AS [FAKTURARAD!2!AKTIVEFFEKT],
	NULL 			AS [FAKTURARAD!2!REAKTIVEFFEKT],
	NULL 			AS [FAKTURARAD!2!PERIODFROM],
	NULL 			AS [FAKTURARAD!2!PERIODTOM],
	NULL 			AS [FAKTURARAD!2!AVLASNINGSDATUM],
	NULL 			AS [FAKTURARAD!2!MATARSTALLNING],
	NULL 			AS [FAKTURAMATARE!3],
	NULL 			AS [FAKTURAMATARE!3!FAKTURAMATAREID],
	NULL 			AS [FAKTURAMATARE!3!MATARID], 
	NULL 			AS [FAKTURAMATARE!3!AVLASNINGSDATUM], 
	NULL 			AS [FAKTURAMATARE!3!MATARSTALLNING] 
FROM FAKTURA
INNER JOIN ENHETER ENHETER ON ENHETER.ENHETSID = FAKTURA.ENHET
WHERE FAKTURA.READYTOEXPORT = 1 AND FAKTURA.EXPORTED = 0
UNION ALL
SELECT 
	2,
	1,
	FAKTURA.FAKTURAID,
	NULL,
	NULL,
	NULL,	
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	--NULL,
	NULL,
	NULL,
	ENHETER.ENHETSNAMN	AS [FAKTURA!1!ENHET],
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	FAKTURARAD.FAKTURAID,
	FAKTURARAD.RADID,
	ARTIKELNAMN.ARTIKELNAMN,
	FAKTURARAD.NOTERING,
	FAKTURARAD.KVANTITET,
	COALESCE (ENHETER.ENHETSNAMN, ''),
	FAKTURARAD.RADBELOPP,
	FAKTURARAD.AKTIVEFFEKT,
	FAKTURARAD.REAKTIVEFFEKT,
	FAKTURARAD.PERIODFROM,
	FAKTURARAD.PERIODTOM,
	FAKTURARAD.AVLASNINGSDATUM,
	FAKTURARAD.MATARSTALLNING,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL
FROM FAKTURA
INNER JOIN FAKTURARAD FAKTURARAD ON FAKTURARAD.FAKTURAID = FAKTURA.FAKTURAID 
INNER JOIN ARTIKELNAMN ARTIKELNAMN ON ARTIKELNAMN.ARTIKELID = FAKTURARAD.ARTIKELID
INNER JOIN  ENHETER ENHETER ON ENHETER.ENHETSID = FAKTURARAD.ENHET
WHERE FAKTURA.READYTOEXPORT = 1 
	AND FAKTURA.EXPORTED = 0
UNION ALL
SELECT
	3,
	1,
	FAKTURA.FAKTURAID,
	NULL,
	NULL,
	NULL,	
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	--NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	FAKTURAMATARE.FAKTURAMATAREID,
	FAKTURAMATARE.MATARID, 
	FAKTURAMATARE.AVLASNINGSDATUM, 
	FAKTURAMATARE.MATARSTALLNING
FROM FAKTURA
INNER JOIN FAKTURAMATARE FAKTURAMATARE ON FAKTURAMATARE.FAKTURAID = FAKTURA.FAKTURAID 
WHERE FAKTURA.READYTOEXPORT = 1 
	AND FAKTURA.EXPORTED = 0
ORDER BY [FAKTURA!1!FAKTURAID],
         [FAKTURARAD!2!RADID!HIDE]

FOR XML EXPLICIT

I am receiving this error
Server: Msg 6833, Level 16, State 1, Line 1
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top