My code
我的代码
RETURNS TABLE
AS
RETURN
(
with Documents as
(
select TOP 100 PERCENT d.LeEn, d.Wacode, d.Waname, d.Arcode, d.Arname, sum(d.Quantity) as Quantity from Documents as d
where (select max(DocumentDate) from Documents as d where d.DocumentCode = 'INW') <= d.DocumentDate
group by d.LeEn, d.WarehouseCode, d.Waname, d.Arcode, d.Arname
order by d.LeEn, d.WarehouseCode, d.Arcode
)
)
and I am getting this
我得到了这个
Incorrect syntax near ')'.
')'附近的语法不正确。
any ideas?
有任何想法吗?
1 个解决方案
#1
3
The WITH
should be before a SELECT
. In this case, the CTE seems unnecessary, so just do:
WITH应该在SELECT之前。在这种情况下,CTE似乎是不必要的,所以只需:
RETURN (
select TOP 100 PERCENT d.LeEn, d.Wacode, d.Waname, d.Arcode, d.Arname, sum(d.Quantity) as Quantity
from Documents as d
where (select max(DocumentDate)
from Documents d
where d.DocumentCode = 'INW'
) <= d.DocumentDate
group by d.LeEn, d.WarehouseCode, d.Waname, d.Arcode, d.Arname
order by d.LeEn, d.WarehouseCode, d.Arcode
)
The ORDER BY
and TOP 100
are utterly superfluous. SQL Server does not guarantee that the results are ordered.
ORDER BY和TOP 100完全是多余的。 SQL Server不保证结果是有序的。
#1
3
The WITH
should be before a SELECT
. In this case, the CTE seems unnecessary, so just do:
WITH应该在SELECT之前。在这种情况下,CTE似乎是不必要的,所以只需:
RETURN (
select TOP 100 PERCENT d.LeEn, d.Wacode, d.Waname, d.Arcode, d.Arname, sum(d.Quantity) as Quantity
from Documents as d
where (select max(DocumentDate)
from Documents d
where d.DocumentCode = 'INW'
) <= d.DocumentDate
group by d.LeEn, d.WarehouseCode, d.Waname, d.Arcode, d.Arname
order by d.LeEn, d.WarehouseCode, d.Arcode
)
The ORDER BY
and TOP 100
are utterly superfluous. SQL Server does not guarantee that the results are ordered.
ORDER BY和TOP 100完全是多余的。 SQL Server不保证结果是有序的。