添加带有日期时间的小时,然后将此时间与当前时间进

时间:2016-11-18 09:31:44

标签: sql sql-server

我使用一个临时表来比较两个列,使用dateadd()来添加Hour。但是在select dateadd()中我只得到一个结果!

如何获取所有记录值?

 DECLARE @temp TABLE (
    ArmouryIssueId INT
    ,Estimatedtime INT
 )

INSERT INTO @temp (
    ArmouryIssueId
    ,Estimatedtime
)
SELECT ArmouryIssueId ,EstimatedTime FROM [ArmouryIssueGun]

DECLARE @StartDate DATETIME
    ,@EndDate DATETIME
    ,@ExpectedTime INT

SELECT @StartDate = CreatedOn FROM [ArmouryIssueGun] AS aig
INNER JOIN @temp TEMP ON aig.ArmouryIssueId = TEMP.ArmouryIssueId

SELECT @ExpectedTime = Estimatedtime FROM @temp

SELECT dateadd(HOUR, @ExpectedTime, @StartDate) AS time_added
    ,@StartDate AS curr_date

1 个答案:

答案 0 :(得分:1)

SELECT DATEADD(HOUR,Estimatedtime,CreatedOn) AS TIME_ADDED,
CREATEDON AS CURR_DATE FROM [ARMOURYISSUEGUN]