Hi,
I have this command in CR.
DECLARE @docEntry AS INT
DECLARE @objectId AS NVARCHAR(20)
SET @objectId = {?ObjectId@}
SET @docEntry = {?DocKey@}
Exec ('WITH Lines AS
(SELECT
NULL AS SpecialLineType,
NULL AS SpecialLineText,
T0.DocEntry,
T0.VisOrder AS ASortCode,
-1 AS BSortCode
FROM rdr1 T0 JOIN ordr T1 ON T0.DocEntry = T1.DocEntry Left Outer join OITM T2 on T2.Itemcode = T0.ItemCode
Left Outer join ITM1 T3 on T3.ItemCode = T2.ItemCode
UNION ALL
SELECT
T21.LineType AS SpecialLineType,
T21.LineText AS SpecialLineText,
T21.DocEntry,
T21.AftLineNum AS ASortCode,
T21.LineSeq AS BSortCode
FROM rdr1 T20 RIGHT JOIN rdr10 T21 ON 1=2
)
SELECT * FROM Lines WHERE DocEntry = '+@docEntry+'
ORDER BY ASortCode, BSortCode')
/* SELECTION - END */
You can test removing the parameters ( {?ObjectId@} {?DocKey@}) by a document that has text.
As far as it is ordered you need to add all your fields
I hope it helps.