【发布时间】:2013-06-25 17:27:48
【问题描述】:
问题:我使用 sql server 数据库上的查询填充了数据表。查询是:
Select ID, startDate, codeID, Param,
(select top 1 startDate from myTable
where ID='" & ID & "' and Param = mt.param and codeID = 82 and startDate >= '" & startDate & "' and startDate >=mt.startDate
ORDER BY startDate)endTime,
from myTable mt where ID = '" & ID & "'
AND (startDate between '" & startDate & "' AND '" & endDate & "' AND (codeID = 81))
我想要一个名为 duration 的新列,它将是 endTime 和 startDate 之间的差异(以毫秒为单位)。我不能只向上述查询添加另一个子查询,因为在运行子查询之前 endTime 列不存在。
那么,有没有办法运行第一个查询来填充数据表,然后运行如下查询:
Select DateDiff(ms,endTime,startDate)
单独将其结果添加到我的数据表中的新列?
【问题讨论】:
-
该代码易受 sql 注入攻击。你实际上是在乞求被黑。