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.
| Author |
Topic |
|
kevin24
Starting Member
13 Posts |
Posted - 2011-12-15 : 23:00:26
|
| Hi,I am new to SQl. I am using version 2008 RC2.I am trying to follow an example stored proceedure using the Northwind database.I copy the example but I get many errors and have been unsuccessful in correcting them.The code is:-CREATE PROCEDURE[dbo].[GetSalesByCategoryWithPaging] @startRowIndex int, @maximumRows INT, @SalesCategoryCnt INT OUTPUT ASBEGIN SELECT @SalesCategoryCnt=(SELECT COUNT(*) FROM (SELECT C.CategoryName, ProductName FROM [Order Details] OD inner join Orders O on O.OrderID = OD.OrderID inner join Products P on P.ProductID = OD.ProductID inner join Categories C on C.CategoryID = P.CategoryID GROUP BY C.CategoryName, ProductName) as salesCategoryCnt ); Declare @currRowIndex INT; set @currRowIndex = (@startRowIndex * @maximumRows) + 1; With SalesEntries as (SELECT ROW_NUMBER() OVER (ORDER BY C.CategoryName ASC) as Row, C.CategoryName, ProductName, TotalPurchase=ROUND(SUM(CONVERT(decimal(14,2), OD.Quantity * (1-OD.Discount) * OD.UnitPrice)), 0) FROM [Order Details] OD inner join Orders O on O.OrderID = OD.OrderID inner join Products P on P.ProductID = OD.ProductID inner join Categories C on C.CategoryID = P.CategoryID GROUP BY C.CategoryName, ProductName ) Select * FROM SalesEntries WHERE Row between @currRowIndex and @currRowIndex+@maximumRows-1 order by CategoryName asc END GOThe errors are:-Msg 102, Level 15, State 1, Line 2Incorrect syntax near ' '.Msg 102, Level 15, State 1, Line 8Incorrect syntax near ' '.Msg 102, Level 15, State 1, Line 9Incorrect syntax near ' '.Msg 102, Level 15, State 1, Line 16Incorrect syntax near ' '.Msg 137, Level 15, State 2, Line 16Must declare the scalar variable "@startRowIndex".Msg 102, Level 15, State 1, Line 19Incorrect syntax near ' '.Msg 102, Level 15, State 1, Line 20Incorrect syntax near ' '.Msg 102, Level 15, State 1, Line 31Incorrect syntax near ' '.Thank you for your kind attention. Kevin |
|
|
sql-programmers
Posting Yak Master
190 Posts |
|
|
kevin24
Starting Member
13 Posts |
Posted - 2011-12-16 : 02:19:20
|
| Hi,Changed the compatibility level to (100)Still get error messages:-Msg 102, Level 15, State 1, Line 3Incorrect syntax near ' '.Msg 102, Level 15, State 1, Line 9Incorrect syntax near ' '.Msg 102, Level 15, State 1, Line 10Incorrect syntax near ' '.Msg 102, Level 15, State 1, Line 17Incorrect syntax near ' '.Msg 137, Level 15, State 2, Line 17Must declare the scalar variable "@startRowIndex".Msg 319, Level 15, State 1, Line 19Incorrect 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.Msg 102, Level 15, State 1, Line 21Incorrect syntax near ' '.Msg 102, Level 15, State 1, Line 32Incorrect syntax near ' '. |
 |
|
|
sql-programmers
Posting Yak Master
190 Posts |
|
|
kevin24
Starting Member
13 Posts |
Posted - 2011-12-16 : 22:51:00
|
| Hi,Removed SQLExpress and now is ok.Many thanks your guidance. |
 |
|
|
|
|
|
|
|