Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Paging data in DataList control

Hi guys,
I've built a SQL query that allows me to page data returned from SQL Server (kinda like 10 records per page view or 5 - depends on the setting), which I want to control using query strings. Everything in my query seems to work brilliant as long as its in SQL Management Studio:

SELECT *
FROM (SELECT TOP (10) *
FROM (SELECT TOP (10 * @page) *
FROM [mytable]
WHERE ([dept] = @deptqs)
ORDER BY [emp_id])
WHERE ([id] NOT IN (SELECT TOP (10 * (@page - 1)) [id]
FROM [mytable]
WHERE ([dept] = @deptqs)
ORDER BY [emp_id]))
ORDER BY [emp_id] DESC)
ORDER BY [emp_id]

However, when I try to use this query in the DataList control's data source config, I get these error messages:

Incorrect syntax near the keyword 'WHERE'.
Incorrect syntax near the keyword 'ORDER'.

I dont see any problems with the query. Any idea what I might be doing wrong here? Please suggest.

Cheers!

Zee
[1012 byte] By [ziggy911] at [2007-11-11 10:31:37]
# 1 Re: Paging data in DataList control
Is it a stored procedure? if so, try executing stored procedure and passing it values manually. sorry dont have any idea what Mangement Studio is.
kashif_82 at 2007-11-11 23:11:46 >