• This is what has worked for me. This code is embedded in a S/P and runs on a schedule and gives me a CSV like clockwork every night. Needs no tweaking of permissions or access, other than turning xp_cmdshell ON and OFF. In addition, bcp is itself used to fire a S/P, not just a static query. Note that the stored procedure name can also be parameterized and works fine. I just leave in plain text for maintainability.

    --turn xp_cmdshell ON as I leave them off by default:

    EXECUTE master.dbo.sp_configure 'show advanced options', 1

    RECONFIGURE

    EXEC master.dbo.sp_configure 'xp_cmdshell', 1

    RECONFIGURE

    SET @SQL = 'bcp "exec [WorkflowV3].[dbo].aStatusExtractDataCSV" queryout "' + @destFolder + @fileName + '" -t \, -T -c'

    EXECUTE master.dbo.xp_cmdshell @SQL

    --and then turn xp_cmdshell back OFF for security's sake

    EXEC master.dbo.sp_configure 'xp_cmdshell', 0

    RECONFIGURE

    EXECUTE master.dbo.sp_configure 'show advanced options', 0

    RECONFIGURE

    Good luck!

    Sigerson

    "No pressure, no diamonds." - Thomas Carlyle