BCP Command for XML Export

  • Hi All,

    I'm trying to run a query to export one of the tables currently sitting in our SQL Server using the following command:

    DECLARE @FileName varchar(50),

    @bcpCommand varchar(8000)

    SET @FileName = 'D:\SQLextracts\OWNER_CDG.SBA_SUBAGENTACCOUNTING'+'.xml'

    SET @bcpCommand = 'bcp "SELECT * FROM [database].[Data Table] FOR XML AUTO, ROOT("[Data Table]''), ELEMENTS" QUERYOUT "'

    SET @bcpCommand = @bcpCommand + @FileName + '" -T -c -r -t'

    PRINT @bcpCommand

    EXEC master..xp_cmdshell @bcpCommand , No_output

    go

    This works for all the other tables I'm extracting, however for this one the output is in .XM format and not .XML .

    Any ideas as to why this is occurring and how I need to go and fix the issue? If more detail is needed let me know.

    Thanks.

  • Your filename is 51 characters long. You declare the variable to be 50 characters long. Truncation occurs.

    -PatP

  • Brilliant, it worked!

    Thanks heaps for the help and the quick response.

    Nathan

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply