I am trying to generate the output result to a .txt file dynamically with whatever the value of @name will be, it will be generated automatically via cursor, just to show an example, I've showed as SET.
Below is the code I am trying to exec, it says incorrect syntax at +
declare @name nvarchar(max); SET @name = 'test1'
exec master..xp_cmdshell 'sqlcmd -s, -W -Q "set nocount on; select * from [EDI].[dbo].[Vendor]" | findstr /v /c:"-" /b > '\\shared data\Everyone\'+@name+'+'.txt'"'
If I just enter the entire path without any variables, the code works perfectly fine.
I have tried bcp too, but its skipping the column headers. So, I've tried to do the union all thing but it throws error saying incorrect column name. Hence trying to use sqlcmd. Please help me out.
Thank you