Hi Richard,
The following should do the trick:
SQLCMD -S <servername> -d <databasename> -U <username> -P <password> -Q "set nocount on;SELECT T0.ItemCode, isnull(T0.FrgnName, '') as FrgnName, isnull(T0.Qrygroup2, 'N') as QryGroup2, U_Dimensions, U_AgeRange, U_Category, cast(T1.OnHand-T1.IsCommited as nvarchar) FROM OITM T0 inner join OITW T1 on T0.ItemCode = T1.ItemCode and T1.WhsCode = '01'" -s "," -o "\\serveraddress\TestBat.csv" -h-1 -s"," -W -w 999
Few things to note:
1) I've added the command 'set nocount on' at the start of the script. This suppresses the message at the end of the file telling you how many records have been returned. You can remove this if you actually want the message.
2) I've put isnull functions around fields that could potentially be null. I wasn't sure on your UDF data types so I left them but I would recommend using isnull for them as well if they could potentially be null.
3) I cast the calculation on OnHand - IsCommitted to a nvarchar as this ensures that it uses 0.00 rather than .00 in the export file. Not sure if that matters in your case but I prefer it ;-)
Kind Regards,
Owen