SQL Server中rowid的替换



我有一个Oracle选择,我需要在SQL Server中执行(表是从Oracle数据库导出到SQL Server数据库)。我可以用isnull代替nvl,用case解码,但是在这种特定情况下如何处理rowid?

select sum(
nvl(
(select sum(b.restsaldo) from reskontro.erkrysskid b
where 1=1
and b.fakturanr = a.fakturanr
and b.kundenr = a.kundenr
and b.resknr = b.resknr
and a.rowid = decode(a.reskfunknr,31,a.rowid,b.rowid)
and nvl(b.restsaldo,0) <> 0
and b.krysskidid <= a.krysskidid
and not exists (select * from reskontro.erkrysskid c
where b.kundenr = c.kundenr
and b.resknr = c.resknr
and a.resklinr < c.resklinr
and a.krysskidid < c.krysskidid
and b.fakturanr = c.fakturanr
and c.reskfunknr in (31,75)
and nvl(c.attfort,-1) = -1)
),0
)
) as restsaldo from reskontro.erkrysskid a 
where 1=1
and a.kundenr = 1 
and a.resknr = 1

SQL Server没有ROWID伪列。在Oracle中,这被用于自连接的上下文中,以确定被连接的两行是否为同一行。在SQL Server中,只需比较表的关键列。

例如,如果表在Id列上有一个键,则使用

and a.Id = case when a.reskfunknr = 31 then a.Id else b.Id end

相关内容

  • 没有找到相关文章