EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
create procedure [dbo].[exportSubmissionsReport]
@login varchar(50) ='x',
@password varchar(10) ='y$',
@Server varchar(50) = 'my/instance',
@Database varchar(50) = 'database_DEMO',
@Statement varchar(5000),
@fileName varchar(70) = 'TESD'
as
declare @query varchar(8000);
set @query = 'sqlps.exe -command "invoke-sqlcmd ';
set @query = @query example@sqldat.com+ ' ';
set @query = @query + ' -ServerInstance 'example@sqldat.com+' -Username ';
set @query = @query + @login+' -Password 'example@sqldat.com+' -Database 'example@sqldat.com+' |Export-CSV E:\NMCMS_DEMO\UploadedMedia\Reports\'example@sqldat.com+'.csv"';
execute xp_cmdshell @query