我使用一个临时表来比较两个列,使用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
答案 0 :(得分:1)
SELECT DATEADD(HOUR,Estimatedtime,CreatedOn) AS TIME_ADDED,
CREATEDON AS CURR_DATE FROM [ARMOURYISSUEGUN]