Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 CTE-parameter

Author  Topic 

inbs
Aged Yak Warrior

860 Posts

Posted - 2013-02-22 : 08:03:58
hi
i have this query,and i want use paramate in cte,
i get the error below, what's the problem?


DECLARE @StockDate AS DATETIME

SET @StockDate = (SELECT LastStockDate FROM FullDateStock)

WITH CTE_getData AS
(
SELECT MAX(CurrDate) AS CurrDate,Product
FROM
WHERE CurrDate<@StockDate
GROUP BY Product
)
SELECT * FROM CTE_getData


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.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2013-02-22 : 08:06:36
quote:
Originally posted by inbs

hi
i have this query,and i want use paramate in cte,
i get the error below, what's the problem?


DECLARE @StockDate AS DATETIME

SET @StockDate = (SELECT LastStockDate FROM FullDateStock)

;WITH CTE_getData AS
(
SELECT MAX(CurrDate) AS CurrDate,Product
FROM fromWhat???
WHERE CurrDate<@StockDate
GROUP BY Product
)
SELECT * FROM CTE_getData


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.




Too old to Rock'n'Roll too young to die.
Go to Top of Page
   

- Advertisement -