I'm trying to use xp_cmbshell by setting up the call as a variable. Just becaues my final select is quite complicated. For this example, I just used a small select.
When I run the following I'm getting an error:
Msg 214, Level 16, State 201, Procedure xp_cmdshell, Line 1
Procedure expects parameter 'command_string' of type 'varchar'.
I also tried casting @sql as varchar, but still the same error. I also tried doing @command_string = @sql and command_string = @sql. But all gives errors. I can run the select fine if I don't have it setup as a variable.
declare @sql as nvarchar(max)
set @sql = 'bcp "SELECT Product_Group_Description FROM Scales_fpnb.dbo.Lookup_Product_Group where product_group_description like ''%pulp%'' for xml auto, type, root(''root'')" queryout c:\test.xml -T -c'
exec xp_cmdshell @sql