• and the same tested query via sqlcmd:

    declare @cmd varchar(4000)

    --sqlcmd -q "select col1,col2,col3 from table" -oc:\myfile.csv -h-1 -s","'

    SELECT @cmd = 'sqlcmd.exe' --the executable...if not in the PATH variable, you might need something like 'C:\Program Files (x86)\Microsoft SQL Server\90\Tools\Binn\bcp.exe '

    + ' ' --space required for parameterizing

    + '-q' -- -q = sqlcmd parameter

    + '"SELECT EMAILTEMPLATESID, EMAILBODY FROM BFONRA.dbo.EMAILTEMPLATES ORDER BY EMAILTEMPLATESID"'

    --<-- the query itself: no CrLf allowed.

    + ' ' -- space required for parameterizing

    + '-o ' -- -o = sqlcmd parameter

    + 'c:\Data\bcpExample3.txt' -- destination file name:

    + ' ' -- space required for parameterizing

    + '-h-1' -- -h = headers -1 = no

    + ' ' -- space required for parameterizing

    + '-s","' -- comma delimited -s"[||]" = field terminator

    EXECUTE master.dbo.xp_cmdshell @cmd

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!