SQLCMD - 从日期和格式字段中删除时间戳到小数点后两位

SQLCMD - removing timestamp from date & formatting fields to 2 decimal places

我正在使用 SQLCMD 从我的服务器导出 SQL 查询。

我正在导出的字段之一是日期字段 - 但在导出时它也有时间戳 - 例如: 2015-12-15 00:00:00.000

如何从日期中删除时间戳,使其成为: 2015-12-15

除此之外 - 在其他具有数值数据的导出字段中,它会自动导出到小数点后 6 位。如何将字段格式化为小数点后两位?

目前 SQLCMD 看起来像这样:

SQLCMD -S <server name> -d <db name> -U <username> -P <password> -Q 
"set nocount on;
SELECT 
T0.DocNum, 
T0.CardCode, 
T0.CardName, 
T0.DocDate, 
T0.DocTime, 
T0.U_FreightEntry, 
T1.ItemCode, 
T1.Dscription, 
T1.CodeBars, 
T1.Quantity, 
(((100-T0.DiscPrcnt)/100)*T1.Price) as 'Price per unit ex GST', 
((((100-T0.DiscPrcnt)/100)*T1.Price)*1.1) as 'Price per Unit Inc GST', 
(SELECT T6.Price FROM ITM1 T6 where T6.ItemCode = T5.Itemcode and T6.PriceList = '2') as 'RRP inc GST per unit', T0.VatSum, T0.DocTotal as 'Inv Total' 
FROM dbo.OINV  T0 INNER JOIN dbo.INV1  T1 ON T0.DocEntry = T1.DocEntry 
INNER JOIN dbo.OCRD  T2 ON T0.CardCode = T2.CardCode 
INNER JOIN dbo.OCRG  T3 ON T2.GroupCode = T3.GroupCode 
INNER JOIN OPLN T4 ON T2.ListNum = T4.ListNum 
INNER JOIN OITM T5 ON T1.ItemCode = T5.ItemCode 
INNER JOIN ITM1 T6 ON T5.ItemCode = T6.ItemCode and T6.Pricelist = '1'
WHERE T3.GroupName = 'NEWSXPRESS' and T0.DocDate = '20151215'
ORDER BY T0.DocNum" 
-s "," -o "<server address>\NewsxpressInvoices_%DATE:~4,2%_%DATE:~7,2%_%DATE:~-4%.csv" -h-1 -s"~" -W -w 999

如有任何帮助,我们将不胜感激。

问候 瑞克

提问前搜索现有答案。

1) How to return the date part only from a SQL Server datetime datatype

SQlServer2008及以上版本:

select CONVERT(date, getdate())

2) Write a number with two decimal places SQL server

SELECT CONVERT(DECIMAL(10,2),YOURCOLUMN)