• You actually posted the way to export a query and the link specifies all the options available.

    Maybe you found this version more readable.

    To copy the previous version is really easy. Just click on the start of the line and go down.

    DECLARE @BCP varchar(8000);

    SET @BCP = 'BCP.exe ' --Command

    + '"SELECT Id, myDate FROM Test.dbo.Test_Dates WHERE myDate IS NOT NULL" ' -- Source

    + 'queryout ' --bcp option

    + '"C:\Table.csv" ' --Datafile

    + '-c ' --character data type

    + '-t"****%*****" ' --field terminator (column delimiter)

    + '-SEKT522038 ' --Server

    + '-T ' --Trusted Connection (Use -U and -P for user and password)

    + '-m10 ' --Maximum number of errors

    + '-e"C:\Table.err" ' --Error file

    + '-o"C:\Table.out"'; --Output file

    EXEC xp_cmdshell @BCP;

    EDIT: If the query is too complex, you could use a stored procedure or a view.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2