I have a query that uses sqlcmd to write a file in a certain folder.
EXEC master..xp_cmdshell'sqlcmd -q "set nocount on; use [myDB] SELECT top 1 T.Field1, T.Fieldn FROM [dbo].[myTable] AS T" -oc:\Outputfolder\FileName.csv -E -m 1 -h2 -s","'
The EXEC Master instruction works fine by it self by inside the trigger, it generates a loop: The file is created but sql got stuck in 'Executing query'
The structure of the trigger is:
ALTER TRIGGER CreateCsvFile_Trigger ON [dbo].[TempProjectCsv] AFTER INSERT
AS
<Variables>
BEGIN
SET NOCOUNT ON;
EXEC master..xp_cmdshell'sqlcmd -q "set nocount on; use [myDB] SELECT top 1 T.Field1, T.Fieldn FROM [dbo].[myTable] AS T" -oc:\Outputfolder\FileName.csv -E -m 1 -h2 -s","'
END
GO
Anyone can tell me why it works fine alone but it breaks from the trigger? As always, thanks!