2

在你们的帮助下,我有以下 SQL 查询:

SELECT DataLog.TimestampUTC,MeterTags.Name,DataLog.Data
FROM DataLog
INNER JOIN MeterTags
ON DataLog.MeterTagId = MeterTags.MeterTagId
WHERE DataLog.TimeStampUTC between cast(getdate() - 1 as date) and cast(getdate() as date) and
      DataLog.MeterTagId Between 416 AND 462;

这将返回带有 YYYY-MM-DD hh:mm:ss 的列“TimestampUTC”。我想在此列中删除时间,只显示 YYYY-MM-DD。

您可以提供的任何帮助将不胜感激。

提前致谢。

4

3 回答 3

2
SELECT convert(char(10), DataLog.TimestampUTC, 120) as TimestampUTC, 
MeterTags.Name,DataLog.Data
FROM DataLog
INNER JOIN MeterTags
ON DataLog.MeterTagId = MeterTags.MeterTagId
WHERE DataLog.TimeStampUTC between cast(getdate() - 1 as date) and cast(getdate() as date) and
      DataLog.MeterTagId Between 416 AND 462;
于 2013-08-22T14:27:19.730 回答
1

在 SQL Server 中,您可以转换为日期

select Convert(Date, Convert(datetime, '2013/01/01 12:53:45'))

结果:

2013-01-01
于 2013-08-22T14:10:27.207 回答
0

你应该使用: CAST(DataLog.TimestampUTC as date)

代码如下所示:

SELECT CAST(DataLog.TimestampUTC as date),MeterTags.Name,DataLog.Data
FROM DataLog
INNER JOIN MeterTags
ON DataLog.MeterTagId = MeterTags.MeterTagId
WHERE DataLog.TimeStampUTC between cast(getdate() - 1 as date) and cast(getdate() as date) and
      DataLog.MeterTagId Between 416 AND 462;
于 2013-08-22T14:43:15.430 回答