I have a table with 6 columns and need to convert that output to .json format and send output to .json format to a folder.
I'm testing only with one column. When I execute the select statement I get the correct output;
select'[' +STUFF((select ',{'+ '"LocationID":"' +LocationID++'"}'FROM ##TABLE FOR XML PATH(''),TYPE).value('.','varchar(MAX)'),1,1,'') +']';
But when I add this select to bcp I get an error copy direction must be either 'in','out' or 'format'
DECLARE @cmd varchar(8000)
SET @cmd = 'bcp "select ''['' +STUFF((select '',{''+ ''"LocationID":"'' +LocationID+''"}''FROM ##TABLE FOR XML PATH(''),TYPE).value(''.'',''varchar(MAX)''),1,1,'') +'']''" queryout T:\filename.json -c -t, -T'
EXEC master..xp_cmdshell @cmd
Tried different things but didn't work. Appreciate your help.