UNC output stored procedure

 --https://www.mssqltips.com/sqlservertip/3499/make-network-path-visible-for-sql-server-backup-and-restore-in-ssms/

EXEC XP_CMDSHELL 'net use H: \\chnet\data\ftp_data\Cloverleaf\datatodss\prod /user:xDailyCensus 5Qp8sAh4NMMpN' EXEC XP_CMDSHELL 'Dir H:' IF OBJECT_ID(N'dbo.tmp', N'U') IS NOT NULL DROP TABLE dbo.tmp CREATE TABLE dbo.tmp ( unit NVARCHAR(max) ,totclosed INT ) --Can we name the output file ptflowclsedbed.csv INSERT INTO dbo.tmp EXEC CrouseCustom_ClosedBedCounts DECLARE @sql VARCHAR(8000) SELECT @sql = 'bcp "select * from dbo.tmp" queryout h:\ptflowclsedbed.csv -c -t, -T -d APF_OLTP -S' + @@servername EXEC master..xp_cmdshell @sql DROP TABLE dbo.tmp EXEC XP_CMDSHELL 'net use H: /delete' --S:\FTP_Data\Cloverleaf\datatodss\test --select @@servername