我试图从视图中获取每一秒的随机数据。基本上,我从表中获取少量数据并使用当前时间进行联合生成随机数据.Bellow是我对View的查询:
SELECT
A,
B,
C,
Status
FROM dbo.table1_data
WHERE (
StartTime <= (SELECT CONVERT(VARCHAR(8), GETDATE(), 108) AS time)
)
Union
Select
'135A' as A,
163993 as B,
CONVERT(VARCHAR(8), GETDATE(), 108) AS C,
ROUND(((6 - 0 -1) * RAND() + 0), 1) as Status
但它并没有在每次执行中添加当前时间戳的新数据。
有人可以帮我吗?
答案 0 :(得分:0)
您转换时间的方式有点不对,请尝试以下方法:
SELECT A, B, C, Status
FROM dbo.table1_data
WHERE CONVERT(TIME(0), StartTime) <= CONVERT(TIME(0), GETDATE())
Union
Select '135A' as A
, 163993 as B
, CONVERT(TIME(0), GETDATE()) AS C
, ROUND(((6 - 0 -1) * RAND() + 0), 1) as Status