将查询从Postgresql转换为SQL Server

时间:2015-03-08 07:17:15

标签: sql-server postgresql

我在Postgresql中有一个查询

WITH RECURSIVE transitive_closure(a, b, distance, path_string)
AS
( SELECT a, b, 1 AS distance,
         a || '.' || b || '.' AS path_string
  FROM edges2

  UNION ALL

  SELECT tc.a, e.b, tc.distance + 1,
         tc.path_string || e.b || '.' AS path_string
  FROM edges2 AS e
  JOIN transitive_closure AS tc ON e.a = tc.b
 WHERE tc.path_string NOT LIKE '%' || e.b || '.%'
)
SELECT a, b, min(distance) AS dist FROM transitive_closure
WHERE a = 1 
GROUP BY a, b
ORDER BY a, dist, b;

我想将其转换为SQL Server,是否有任何工具或有人可以为我转换它?

1 个答案:

答案 0 :(得分:0)

recursive不是SQL Server中的关键字。您可以删除它,with在SQL Server中默认是递归的。

在SQL Server中,您可以添加以下字符串:

'Hello ' + 'World'

因此请将||替换为+