{"id":31812,"date":"2026-01-30T11:08:16","date_gmt":"2026-01-30T11:08:16","guid":{"rendered":"https:\/\/www.greytrix.com\/blogs\/sagex3\/?p=31812"},"modified":"2026-01-30T11:46:42","modified_gmt":"2026-01-30T11:46:42","slug":"generating-comma-separated-values-in-sage-x3-excel-reports-using-stuff-sql-server","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/sagex3\/2026\/01\/30\/generating-comma-separated-values-in-sage-x3-excel-reports-using-stuff-sql-server\/","title":{"rendered":"Generating Comma-Separated Values in Sage X3 Excel Reports Using STUFF (SQL Server)"},"content":{"rendered":"\n<p><a href=\"https:\/\/www.greytrix.com\/sage-x3-erp\/development-services\/\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/www.greytrix.com\/sage-x3-erp\/development-services\/\" rel=\"noreferrer noopener\">Sage X3<\/a> is built to support real-life business scenarios, such as creating a single invoice from multiple sales orders or deliveries, and applying multiple payment or receipt entries to one invoice. However, when this information is presented in reports\u2014especially Excel reports\u2014it is often displayed across multiple rows. This leads to repeated invoice details, making the report lengthy and difficult to read.<\/p>\n\n\n\n<p>From a business user\u2019s perspective, related references\u2014such as sales order numbers or payment\/receipt entry numbers along with their dates\u2014are expected to be consolidated and displayed clearly against a single invoice, typically in a comma-separated format.<\/p>\n\n\n\n<p>By combining these related details into a single, comma-separated view, reports become more compact, easier to understand, and visually cleaner. This not only enhances readability but also results in a more professional and business-friendly report output.<\/p>\n\n\n\n<p>Recently, one of our Sage X3 clients requested exactly this enhancement: to display multiple payment or receipt entry numbers and their corresponding dates against a single invoice number in an Excel report.<\/p>\n\n\n\n<p><strong>Example Scenario<\/strong><\/p>\n\n\n\n<p>As shown in Figure 1, there are two separate payment\/receipt entries recorded against a single invoice number. In the standard report output, these entries appear in separate rows, resulting in repeated invoice information.<\/p>\n\n\n\n<p><strong>New Stuff:<\/strong> <a href=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/2026\/01\/29\/seamless-isd-distribution-in-sage-x3\/\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/2026\/01\/29\/seamless-isd-distribution-in-sage-x3\/\" rel=\"noreferrer noopener\">Seamless ISD Distribution in Sage X3<\/a><\/p>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2026\/01\/Figure-1-Example-Entry.jpg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2026\/01\/Figure-1-Example-Entry.jpg\" alt=\"Figure 1 Example Entry\"><\/a><\/center>\n<font size=\"2\"><center>Figure 1 Example Entry<\/center><\/font>\n\n\n\n<p>Instead of displaying each payment or receipt entry on a separate line, the requirement is to combine all related entries and display them in a single cell, separated by commas. This provides a cleaner and more readable report format.<\/p>\n\n\n\n<p>To achieve this consolidation, we can use the following SQL function:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>FOR XML PATH(&#8221;): Combines multiple rows into a single text string by concatenating each entry.<\/li>\n\n\n\n<li>Leading comma: Adds a comma before each value during concatenation to clearly separate the entries.<br>-STUFF(\u2026, 1, 1, &#8221;): Removes the first comma from the combined string, resulting in a clean, properly formatted comma-separated list.<\/li>\n<\/ul>\n\n\n\n<p>The figure 2 below illustrates an example implementing this query.<\/p>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2026\/01\/Figure-2-Query.jpg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2026\/01\/Figure-2-Query.jpg\" alt=\"Figure 2 Query\"><\/a><\/center>\n<font size=\"2\"><center>Figure 2 Query<\/center><\/font>\n\n\n\n<p>After applying the FOR XML PATH(&#8221;) and STUFF functions, all payment or receipt entries related to a single invoice are consolidated and displayed in one cell, separated by commas, within the Sage X3 Excel report. This approach eliminates duplicate rows, enhances report readability, and makes the data easier to review and analyze.<\/p>\n\n\n\n<p>An example of the final output is shown in Figure 3, where the comma-separated values are clearly displayed against a single invoice number.<\/p>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2026\/01\/Figure-3-Comma-Seprated-Output.jpg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2026\/01\/Figure-3-Comma-Seprated-Output.jpg\" alt=\"Figure 3 Comma Separated Output\"><\/a><\/center>\n<font size=\"2\"><center>Figure 3 Comma Separated Output<\/center><\/font>\n\n\n\n<p>After incorporating the query into the Crystal Report and exporting the report to Excel, the output appears as shown below. This confirms that multiple payment or receipt entries are successfully consolidated into a single cell, resulting in a clearer and more user-friendly Excel report.<\/p>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2026\/01\/Figure-4-Comma-Seprated-Excel-Output-1024x389.jpg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2026\/01\/Figure-4-Comma-Seprated-Excel-Output-1024x389.jpg\" alt=\"Figure 4 Comma Separated Excel Output\"><\/a><\/center>\n<font size=\"2\"><center>Figure 4 Comma Separated Excel Output<\/center><\/font>\n\n\n\n<p>Thus the above approach effectively addresses a common reporting challenge in Sage X3 by consolidating multiple related entries into a single, comma-separated format, resulting in cleaner, more readable, and more professional Excel reports.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sage X3 is built to support real-life business scenarios, such as creating a single invoice from multiple sales orders or deliveries, and applying multiple payment or receipt entries to one invoice. However, when this information is presented in reports\u2014especially Excel reports\u2014it is often displayed across multiple rows. This leads to repeated invoice details, making the\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/2026\/01\/30\/generating-comma-separated-values-in-sage-x3-excel-reports-using-stuff-sql-server\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,13],"tags":[4524,644,750,1318,1653],"class_list":["post-31812","post","type-post","status-publish","format-standard","hentry","category-sage-erp-x3","category-integration","tag-comma-separated","tag-duplicate","tag-excel","tag-multiple","tag-report"],"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/posts\/31812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/comments?post=31812"}],"version-history":[{"count":9,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/posts\/31812\/revisions"}],"predecessor-version":[{"id":31822,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/posts\/31812\/revisions\/31822"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/media?parent=31812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/categories?post=31812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/tags?post=31812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}