SQL Server 字符串和时间相互转换
select convert(smalldatetime, convert(char(10),SSD_SellRecord.VoucherTime,120)) as VoucherTime
from SSD_SellRecord group by convert(smalldatetime, convert(char(10),SSD_SellRecord.VoucherTime,120))
因为要根据日期来group by,所以用convert(char(10),SSD_SellRecord.VoucherTime,120)截取日期部分。又因为我们希望的最终结果是时间类型,所以还得用convert(smalldatetime, convert(char(10),SSD_SellRecord.VoucherTime,120))进行转换。
from SSD_SellRecord group by convert(smalldatetime, convert(char(10),SSD_SellRecord.VoucherTime,120))
因为要根据日期来group by,所以用convert(char(10),SSD_SellRecord.VoucherTime,120)截取日期部分。又因为我们希望的最终结果是时间类型,所以还得用convert(smalldatetime, convert(char(10),SSD_SellRecord.VoucherTime,120))进行转换。
浙公网安备 33010602011771号