Tonmoy Saha Tonmoy Saha - 20 days ago 6
SQL Question

Add Hour with date time then compare this time with current time

I am using one temp table to compare between two column using dateadd() for adding Hour. but in select dateadd() I am getting only one result!

How to get all record values?

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

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