1

我对此很陌生。我需要在此查询的单独列中了解 t.1start 和 t1.finish 之间的天数差异。

谢谢,路易

SELECT ROW_NUMBER() OVER(ORDER BY TOWN) AS 'row', 
T1.Surname,
T1.Forename,
T1.Town,
T1.Description,
T1.Sex,
T1.DOB,
T1.start,
T1.finish,
FROM dbo.viewServiceContractFull T1 
WHERE
T1.finish>='2013/01/01'
and 
T1.finish<='2013/01/31'

我现在如何让某些城镇出现在查询中?

4

3 回答 3

1

在 SQL Server 中,您可以使用

SELECT DATEDIFF (MyUnits, '2010-01-22 15:29:55.090', '2010-01-22 15:30:09.153')
于 2013-04-09T06:46:32.177 回答
0

您可以使用DATEDIFF函数来确定两个日期之间的间隔,如果需要,您可以使用CAST/CONVERT将字符串日期转换为实际日期,例如:

CAST('2010-01-22 15:29:55.090' AS DATETIME)

CONVERT 功能使您可以选择日期的格式。

于 2013-04-09T06:44:35.777 回答
0
SELECT ROW_NUMBER() OVER(ORDER BY TOWN) AS 'row', 
T1.Surname,
T1.Forename,
T1.Town,
T1.Description,
T1.Sex,
T1.DOB,
T1.start,
T1.finish, cast(DATEDIFF(DAY,T1.start,T1.finish) as varchar) as difference
FROM dbo.viewServiceContractFull T1 
WHERE
T1.finish>='2013/01/01'
and 
T1.finish<='2013/01/31'

另外看看这个

于 2013-04-09T06:47:48.610 回答