嘿,我一直试图将数据库从Oracle转换为Sql Server格式,这是我遇到问题的一条线,我将在这里感谢一些帮助。
Oracle专栏:
TRUNC(CASE WHEN (b.rsn IS NOT NULL OR A.zeroreport = 1) AND b.datereceived IS NULL THEN A.datereceived ELSE b.datereceived END),
我一直在尝试将其转换为SQl Server,到目前为止我得到了:
CASE WHEN(b.rsn IS NOT NULL或A.zeroreport = 1)和b.datereceived IS NULL,然后A.datereceived ELSE b.datereceived END
, 但不确定这是否正确。我刚刚删除了trun(不确定我是否需要它)
答案 0 :(得分:0)
您正在使用trunc
获取日期部分。您可以通过转换为日期在SQL Server中执行此操作。我想我会选择:
(CASE WHEN (b.rsn IS NOT NULL OR A.zeroreport = 1) AND b.datereceived IS NULL
THEN CAST(A.datereceived as DATE)
ELSE CAST(b.datereceived as DATE)
END),
或者,如果您更喜欢CONVERT()
,则使用CASE
作为第一个参数更容易阅读:
CONVERT(DATE,
(CASE WHEN (b.rsn IS NOT NULL OR A.zeroreport = 1) AND b.datereceived IS NULL
THEN A.datereceived
ELSE b.datereceived
END),
)