In the SQL Docs (xp_cmdshell (Transact-SQL) - Result Sets) it mentions that xp_cmdshell should output as an nvarchar(255)
column
Result Sets
Executing the following xp_cmdshell statement returns a directory listing of the current directory.
EXEC xp_cmdshell 'dir *.exe'; GO
The rows are returned in an nvarchar(255) column. If the no_output option is used, only the following will be returned:
The command(s) completed successfully.
However, when using xp_cmdshell (On SQL Server 2019) it seems to be returning the data as varchar. For example, the below script has a unicode character (Latin capital O) being inserted into a temp table of column nvarchar and returned directly from xp_cmdshell:
Create Table #Temp ([nvarchar] NVARCHAR(100))
Insert into #Temp Values (N'Ȭ')
Select * from #Temp
Outputs 'Ȭ'
exec xp_cmdshell N'echo Ȭ'
Outputs '?'
I'd like xp_cmdshell to handle unicode characters ideally, but don't understand why this is different from the documentation. I did check and command prompt is able to display this character when run normally