 IF OBJECT_ID('dbo.usp_bcpTableUnload', 'P') IS NULL EXECUTE ('CREATE PROCEDURE dbo.usp_bcpTableUnload AS SELECT 1');
-go
-
-ALTER PROCEDURE dbo.usp_bcpTableUnload (
+GO
+
+ALTER PROCEDURE [dbo].[usp_bcpTableUnload](
       @path                NVARCHAR(900)
-    , @serverName          SYSNAME = @@SERVERNAME
+    , @serverName          SYSNAME       = @@SERVERNAME
     , @databaseName        SYSNAME
     , @schemaName          SYSNAME
     , @tableName           SYSNAME
-    , @field_term          NVARCHAR(10)  = '|'
-    , @row_term            NVARCHAR(10)  = '\n'
-    , @fileExtension       NVARCHAR(10)  = 'txt'
-    , @codePage            NVARCHAR(10)  = 'C1251'
-    , @excludeColumns      NVARCHAR(MAX) = ''
-    , @orderByColumns      NVARCHAR(MAX) = ''
-    , @outputColumnHeaders BIT = 1
-    , @debug               BIT = 0
+    , @field_term          NVARCHAR(10)  = N'|'
+    , @row_term            NVARCHAR(10)  = N'\n'
+    , @fileExtension       NVARCHAR(10)  = N'txt'
+    , @codePage            NVARCHAR(10)  = N'C65001'
+    , @excludeColumns      NVARCHAR(MAX) = N''
+    , @orderByColumns      NVARCHAR(MAX) = N''
+    , @outputColumnHeaders BIT           = 1
+    , @savePhysicalOrder   BIT           = 1     -- 0 - Alphabet column order type; 1 - physical column order type
+    , @formatFile          VARCHAR(4)    = 'xml' -- formatfile = @schemaName.@tableName.fmt, -x formatfile = @schemaName.@tableName.xml, blank string without generation format file
+    , @collation           VARCHAR(128)  = ''    -- blank for keep blank value in formatfile (formatfile value 1 needed)
+    , @debug               BIT           = 0
 )
 AS
 /*
-bcp docs: https://msdn.microsoft.com/ru-ru/library/ms162802.aspx
+bcp docs: https://docs.microsoft.com/en-us/sql/tools/bcp-utility
 -- To allow advanced options to be changed.
 EXEC sp_configure 'show advanced options', 1;
 GO


    IF @debug = 1 PRINT ISNULL('/******* Start Debug' + @crlf + '@tableFullName = {' + CAST(@tableFullName AS NVARCHAR(MAX)) + '}', '@tableFullName = {Null}');
    IF @debug = 1 PRINT ISNULL('@object_id = {' + CAST(@object_id AS NVARCHAR(MAX)) + '}', '@object_id = {Null}');

    IF @object_id IS NULL THROW 50000, @TROW50000, 1
    IF @orderByColumns <> ''

RECONFIGURE;
GO
EXECUTE [dbo].[usp_bcpTableUnload]
      @path                = N'd:\'
    , @databaseName        = N'DatabaseName'
    , @schemaName          = N'dbo'
    , @tableName           = N'TableName'
    , @field_term          = N'|'
    , @row_term            = N'\n'
    , @fileExtension       = N'txt'
    , @excludeColumns      = N'[CreatedDate],[ModifiedDate],[UserID]'
    , @orderByColumns      = N'TableNameID'
    , @outputColumnHeaders = 1
    , @formatFile          = N'xml'
    , @debug               = 0;
*/
BEGIN
