when i execute this query, i get error of ‘Incorrect syntax near the keyword ‘VIEW”
please help me, what is the problem in this query?
EXECUTE sp_executesql
N'
CREATE VIEW LastDayOfMonth
AS
SELECT @MAX = MAX(DATEPART(DAY,CurrencyRateDate))AS CurrencyRateDate FROM Sales.CurrencyRate
WHERE
DATEPART(YEAR,CurrencyRateDate)=@YEAR
AND
DATEPART(MONTH,CurrencyRateDate)= @MONTH',
N' @YEAR CHAR(4),@MONTH CHAR(2)',
@YEAR = '2004',
@MONTH = '02';
There’s no obvious reason to do what you’re doing here either using a view or using
sp_executesql.The following should work:
and to show the result:
If this isn’t what you’re trying to do, perhaps you could edit the question and clarify?