Các truy vấn sau đây:Bắt lỗi lẻ, truy vấn SQL Server sử dụng `WITH` khoản
WITH
CteProductLookup(ProductId, oid)
AS
(
SELECT p.ProductID, p.oid
FROM [dbo].[ME_CatalogProducts] p
)
SELECT
rel.Name as RelationshipName,
pl.ProductId as FromProductId,
pl2.ProductId as ToProductId
FROM
(
[dbo].[ME_CatalogRelationships] rel
INNER JOIN CteProductLookup pl
ON pl.oid = rel.from_oid
)
INNER JOIN CteProductLookup pl2
ON pl2.oid = rel.to_oid
WHERE
rel.Name = 'BundleItem' AND
pl.ProductId = 'MX12345';
Là tạo ra lỗi này:
Msg 319, Level 15, State 1, Line 5 Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
On thực hiện chỉ. Không có lỗi/cảnh báo trong câu lệnh sql trong studio quản lý.
Bất kỳ ý tưởng nào?
tại sao thậm chí sử dụng một CTE đây? bạn không thể chỉ cần tham gia vào bảng thực tế '[dbo]. [ME_CatalogProducts]' thay vì cte 'CteProductLookup', mà không thực sự làm gì cả? –
Để gia hạn sau, nhưng bạn nói đúng Tôi không cần nó trong ví dụ này. – Aren