关于sql server查询

时间:2012-05-28 10:43:42

标签: sql sql-server

这是我在sql中的查询:

with cte
as(
  select top 1 
    Id,
    (((DATEPART(hour, CAST([Time] AS DATETIME)) * 60) + (DATEPART(minute, CAST([Time] AS DATETIME)) ) )) AS Tim,
    Price
 from Prices order by [Time] desc
)
,cte1 as(
  select 
    (((DATEPART(hour, CAST([Time] AS DATETIME)) * 60) + (DATEPART(minute, CAST([Time] AS DATETIME)) ) )) as tim1
  from M1 
)

现在我想这样做;如果cte.tim = cte1.tim1,更新表中的一行,否则插入表中,但我不知道如何? 非常感谢

1 个答案:

答案 0 :(得分:0)

您只能同时制作SELECTUPDATE,而不能同时制作两者!

查看this MSDN article了解详情。