{"title":"Query.SaveAsCsv(OutStream [, Integer] [, Text]) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/query/queryinstance-saveascsv-outstream-integer-string-method/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/query/queryinstance-saveascsv-outstream-integer-string-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/query/queryinstance-saveascsv-outstream-integer-string-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Saves the resulting data set of a query as comma separated values (CSV)","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"Query.SaveAsCsv(OutStream [, Integer] [, Text]) Method","slug":"querysaveascsvoutstream-integer-text-method","at":0,"chars":1658},{"level":2,"title":"Syntax","slug":"syntax","at":189,"chars":113},{"level":2,"title":"Parameters","slug":"parameters","at":302,"chars":990},{"level":2,"title":"Return Value","slug":"return-value","at":1292,"chars":233},{"level":2,"title":"Related information","slug":"related-information","at":1525,"chars":133}],"text":"# Query.SaveAsCsv(OutStream [, Integer] [, Text]) Method\n> Version: _Available or changed with runtime version 1.0._\nSaves the resulting data set of a query as comma separated values (CSV)\n## Syntax\n```al\n[Ok := ]  Query.SaveAsCsv(OutStream: OutStream [, Format: Integer] [, FormatArgument: Text])\n```\n## Parameters\nQuery\nType: query-data-type\nAn instance of the query-data-type data type.\nOutStream\nType: ../outstream/outstream-data-type\nThe stream that you want to save the query as CSV to.\n*[Optional] Format*\nType: ../integer/integer-data-type\nSpecifies whether the columns of the resulting data set are at fixed positions in the CSV file or separated only by a delimiter.\n*[Optional] FormatArgument*\nType: ../text/text-data-type\nYou set the FormatArgument parameter based on the setting of the Format parameter. If the Format parameter is set to 0, then the FormatArgument parameter specifies the starting position of each column in the data set. The value is a comma separated string of integers that includes an integer for every column. In a CSV file, each line is evenly divided into positions for holding characters. The first integer corresponds to the starting position of the first column, the second integer corresponds to the starting position of the second column, and so on.\n## Return Value\n*[Optional] Ok*\nType: ../boolean/boolean-data-type\ntrue if the SaveAsCsv succeeded, otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.\n## Related information\nquery-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}