2015-02-04 64 views
1

我需要將ElapsedTime字段轉換爲小時/分鐘/秒並將其添加到創建時間字段並將結果報告到新列我會打電話給EndTime。下面是該查詢我要收集數據:如何將數值作爲秒添加到日期時間字段並報告新列中的數據

select 
ElapsedTime, ChannelUsed, documents.creationtime 
from 
historytrx (nolock) inner join 
history on 
historytrx.handle = history.handle inner join 
documents on 
history.owner = documents.handle inner join 
DocFiles on 
documents.docfiledba = docfiles.handle 
where 
creationtime > '2015-02-02 20:00:00.000' and 
creationtime < '2015-02-02 20:01:00.000' and 
RemoteServer = 'DMG4120-01668' and 
ElapsedTime != '0' 

這裏是電流輸出:

ElapsedTime ChannelUsed creationtime 
1042   1    2015-02-02 20:00:03.000 
27   35    2015-02-02 20:00:05.000 
57   50    2015-02-02 20:00:05.000 

這是我想要的輸出:

ElapsedTime ChannelUsed creationtime    EndTime 
1042   1    2015-02-02 20:00:03.000 2015-02-02 20:17:39.000 
27   35    2015-02-02 20:00:05.000 2015-02-02 20:00:32.000 
57   50    2015-02-02 20:00:05.000 2015-02-02 20:01:03.000 

感謝大家提前任何協助。

+0

搜索DateAdd(),應該給你你想要的... – Sparky

回答

0

嘗試:

select 
ElapsedTime, 
ChannelUsed, 
creationtime, 
convert(datetime, dateadd(ss,elapsedtime,creationtime), 121) as endTime 
from 
historytrx t inner join 
history h on 
t.handle = h.handle inner join 
documents d on 
h.owner = d.handle inner join 
DocFiles f on 
d.docfiledba = f.handle 
where 
creationtime > '2015-02-02 20:00:00.000' and 
creationtime < '2015-02-02 20:01:00.000' and 
RemoteServer = 'DMG4120-01668' and 
ElapsedTime != '0' 

看到this

HTH

0

嘗試這種情況:

select 
    ElapsedTime, ChannelUsed, documents.creationtime, 
    dateAdd(ss,ElapsedTime,documents.creationtime) as EndTime 
    from 
    historytrx (nolock) inner join 
    history on 
    historytrx.handle = history.handle inner join 
    documents on 
    history.owner = documents.handle inner join 
    DocFiles on 
    documents.docfiledba = docfiles.handle 
    where 
    creationtime > '2015-02-02 20:00:00.000' and 
    creationtime < '2015-02-02 20:01:00.000' and 
    RemoteServer = 'DMG4120-01668' and 
    ElapsedTime != '0' 

的使用DateAdd()函數3個參數。 ss代表秒,第二個參數是要添加的秒數,第三個是將秒值添加到的開始日期。

相關問題