La seguente query:Ottenere un errore strano, query SQL Server utilizzando `clausola with`
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';
sta generando questo errore:
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.
Su esecuzione solo. Non ci sono errori/avvertenze nell'istruzione sql nello studio di gestione.
Qualche idea?
perché anche utilizzare un CTE qui? non potresti semplicemente unirti alla tabella reale '[dbo]. [ME_CatalogProducts]' invece di cte 'CteProductLookup', che in realtà non fa nulla? –
Per l'estensione più tardi, ma hai ragione non ne ho bisogno in questo esempio. – Aren