Simulate ROW_NUMBER () In SQL 2000
Nov 22, 2005I would like to generate an incrementing column value to each row found in a query in SQL Server 2000.
View 13 RepliesI would like to generate an incrementing column value to each row found in a query in SQL Server 2000.
View 13 RepliesHi,
I have used ROW_NUMBER() ranking function in a procedure (SQL 2005) for filtering purpose.
Now I want to do the same functionality in SQL 2000.
How to do this?
Thanks
Somu
Can anybody know ,how can we add builtin functions(ROW_NUMBER()) of Sql Server 2005 into database library.
I get this error when i used into storeprocedure :
ROW_NUMBER() function is not recognized in store procedure.
i used MS SQL SERVER 2005 , so i think "ROW_FUNCTION()" is not in MS SQL SERVER 2005 database library.
I need to add that function into MS SQL SERVER 2005 database library.
Can anbody know how we can add that function into MS SQL SERVER 2005 database library?
I am referring to the group concatenation where we get all the values of a single column (of all the rows) grouped into one cell as a concatenated string. I know I can achieve this using temporary tables and cursors in SQL Server. But I cannot have a cursor in SQL CE. I need to add this as a command to a tableadapter in a Dataset Designer. Please let me know if you can think of a workaround.
This is what I want:
Table 1:
Col1 Col2
1 a
1 b
2 c
2 d
2 e
Resultset should be:
Table 2:
Col1 Col2
1 a, b
2 c, d, e
How can I simulate 1,000 simultaneous users in my database?
View 3 Replies View RelatedI have a merge where the subscriber can do changes to its tables ... But as I found out the changes are made only if publisher simulate an row change or changes something effectively
I'm not sure that at every replication the publisher table would be changed so i need something to simulate a change in the publisher table
Can anyone please help me with this ?
I want to simulate 100 users simultaneously executing a procedure in sql server (best example would be 100 users using one report with different parameters in ssrs at the same time ). can i do that ?
View 3 Replies View RelatedI have a table (let's call it MyTable) that consists of four fields:
Id, Source, FirstField, and
SecondField, where Source only takes one of two values:
Source1 and Source2.
The records in this table look as follows:
Id
Source
FirstField
Secondfield
1
Source1
Product 3 name
Product 3 description
[code]...
I need to return, using 3 different T-SQL queries:
1) Products that exist only in Source2 (in red above)
2) Products that exist only in Source1 (in green above)
3) Products that exist both in Source1 and Source2 (in black above)
For 1) so far I've been doing something along the lines of SELECT * FROM MyTable WHERE Source=Source1 AND FirstField NOT IN (SELECT DISTINCT (FirstField) FROM MyTable WHERE Source=Source2)
I have read about INTERSECT and EXCEPT, but I am a little unclear if they could be applied in this case out of the box.
In my fact table (month granularity), I've got a calculation defined:Â
Margin%=DIVIDE(SUM(Margin);SUM(SalesAmount))
How should I define a calculation based on "Margin%", so that if I browse the Pivot Table by months it would always show the year level result instead? My date dimension is also with Month granularity and it has a Year column in it.Â
Here's the scenario. I have a table (let's call it MyTable) that consists of four fields: Id, Source, FirstField, and SecondField, where Source only takes one of two values: Source1 and Source2.
The records in this table look as follows:
I need to return, using 3 different T-SQL queries:
1) Products that exist only in Source2 (in red above)
2) Products that exist only in Source1 (in green above)
3) Products that exist both in Source1 and Source2 (in black above)
For 1) so far I've been doing something along the lines of
SELECT * FROM MyTable WHERE Source=Source1 AND FirstField NOT IN (SELECT DISTINCT(FirstField) FROM MyTable WHERE Source=Source2)
Not being a T-SQL expert myself, I'm wondering if this is the right or more efficient way to go. I have read about INTERSECT and EXCEPT, but I am a little unclear if they could be applied in this case out of the box.
Hi
I am currently developing a DBA management console for a company who have 45 SQL Servers, 20 of which are in the production environment. As part of the development I have created a DBA dashboard with various alerts and information dials regarding the state of the SQL Infrastructure. I came accross a problem yesterday that I cannot find the answer to.
One of the alerts I have developed is a simple "Heart Beat" indicator that displays that the SQL Server is present and "alive". To do this I have a central database running on SQL 2005 which has linked server connections toall 45 SQL Servers. This central database runs a simple select statement on each server (something that I know works if the server is there). The select is run as dynamic SQL as I need to build up the SQL as part of a cursor to place the server name within the from clause. Here is the select I am using: -
select top 1 dbid from [server].master.dbo.sysdatabases
If the server is not there an error occurrs. I trap this and record that the server may not be present. The cursor then moves on to the next server to check.
This works fine when ran from Query Analyser. I can simulate a failed server by deleting the link server connection. For the server in questions an error is raised when the select is run, I store the error and on the Dashboard screen you can see an indicator saying that the server is currently non-contactable (i.e. failed Heart Beat).
My problem comes when I try and schedule this procedure. If I run it as an SQL Agent Job it behaves differently. Here, as soon as the error is detected it bombs out stating that the step has failed. I don't mind it stating that the step has failed, what I want it to do is to complete the cursor loop on all the servers. You see at the top of the procedure I set all the heartbeats flags to 0 (i.e. not contactable) so I need to to complete the run. I have search the Agent set-up and can find no flag to stop it halting processes when an error occurs.
The servers are configured not to allow RPC and I would rather not have to put a job on every server to tell me they exist as this would need managing going forward.
Any help you can offer would be greatly appreciated - Happy New Year by the way!
Hi,
This is my view in Sql2005
SELECT DISTINCT VLAN8, 'CONV' AS VLEDUS, MAX(CAST(VLEDBT AS int)) AS MaxVLEDBT
FROM JDE_DEVELOPMENT.TESTDTA.F06116Z1
GROUP BY VLAN8, VLEDUS
2111CONV2111
4803CONV31
7550CONV33
When I add row number function the results become wrong:
SELECT DISTINCT VLAN8, 'CONV' AS VLEDUS, ROW_NUMBER() OVER (ORDER BY VLAN8) AS VLEDLN, MAX(CAST(VLEDBT AS int)) AS MaxVLEDBT
FROM JDE_DEVELOPMENT.TESTDTA.F06116Z1
GROUP BY VLAN8, VLEDUS, VLEDLN
2111 CONV 1 2111
4803 CONV 2 31
4803CONV3 31
4803CONV4 31
4803CONV5 31
4803CONV6 31
4803CONV7 31
4803CONV8 31
4803CONV931
4803CONV1031
4803CONV1131
4803CONV1231
7550CONV1333
7550CONV1433
7550CONV1533
7550CONV1633
I just need to have :
2111CONV 1 2111
4803CONV 2 31
7550CONV 3 33
Please help me.
I'm using SQL Server 2005, sp 2. My query is below. What I want to see for the results is the average of all of partition 1, the average of partition 2, etc. Does anybody know how I can get this?
SELECT ROW_NUMBER() OVER (PARTITION BY Shop.Location_Code ORDER BY Shop.Date_Code) AS [PARTITION],
(Score) AS [This Year], Shop.Date_Code, Shop.Location_Code
FROM ETL.Transform_FactOpsMSScorecard SHOP INNER JOIN DW_DatamartDB.dbo.DimDate DD
ON Shop.Date_Code=DD.Date_Code
INNER JOIN DW_DatamartDB.dbo.DimLocation LOC ON
Shop.Location_Code = Loc.Location_Code
WHERE District_Code = (@District)
Results:
Partition This Year Date Code Location Code
1 .85 20070101 1
2 .58 20070509 1
1 .52 20070808 2
2 .54 20070905 2
3 .26 20070104 3
3 .26 20070905 3
Hi,
After I read some article about Row_Number() and CTE, I still don't know What they are used for.
Can anyone explain to you?
Thank you
I'm trying to create this stored Procedure:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[iumm_PagerData]
@PagerIndex INT,
@NumRows INT,
@PicsCount INT OUTPUT
AS
BEGIN
SELECT @PicsCount=(SELECT COUNT(*) FROM pics)
Declare @startRowIndex INT;
set @startRowIndex = (@PagerIndex * @NumRows) + 1;
With PicEntries as (
SELECT ROW_NUMBER() OVER (ORDER BY picID DESC) AS Row, picID, userID, picFileName, votes, date FROM pics)
-- Insert statements for procedure here
SELECT picID, userID, picFileName FROM pics WHERE Row between @startRowIndex and @StartRowIndex+@NumRows-1
END
GO
---
However, I'm always getting this error:
Msg 207, Level 16, State 1, Procedure iumm_PagerData, Line 22
Invalid column name 'Row'.
Msg 207, Level 16, State 1, Procedure iumm_PagerData, Line 22
Invalid column name 'Row'.
Anyone knows what could be the reason for that? Thanks.
I'm not sure if this is possible and have been having trouble figuring out the code to do this. I am assigning row_number to a gridview. I then want to filter the results with a dropdown. I am able to get the filter to filter the status but it either renumbers the gridview or it leaves the row numbers blank. Is there a way to have the row_numbers stick to the gridview when I filter? Example below. Thanks
Normal:IssueNumber(row_number), Status1, Open2, Open3, Closed4, Open5, Closed
"Open" Filter:IssueNumber(row_number), Status1, Open2, Open4, Open
"Closed" Filter:IssueNumber(row_number), Status3, Closed5, Closed
Hi,
My application runs this query using a stored proc
SELECT empid1,name1,joindate from emp where empid2=3
union
select empid2,name2,joindate from emp where id1=3
Now I want to implement paging for the same using Row_Number so that I can display the results in pages.
Can someone please help me write a query for the same. I tried playing with Row_Number but no luck with it.Basically I am not good with SQL and I had programatically implemented paging in asp.net by looping through all records returned by the query.
Thanks,
Ganesh
Hi, I am attempting to implement a custome paging solution for my web Application, I have a table that has 30,000 records and I need to bw able to page through these using a Gridview. Here is my curent code but it generates an error when I try to compile the Stored Procedure, I get the following errors:<Error messages> These are on the first SELECT Line..Msg 4104, Level 16, State 1, Procedure proc_NAMEGetPaged, Line 17The multi-part identifier "dbo.NAME.CODE" could not be bound.Msg 4104, Level 16, State 1, Procedure proc_NAMEGetPaged, Line 17The multi-part identifier "dbo.NAME.LAST_NAME" could not be bound.Msg 4104, Level 16, State 1, Procedure proc_NAMEGetPaged, Line 17The multi-part identifier "dbo.NAME.FIRST_NAME" could not be bound.Msg 4104, Level 16, State 1, Procedure proc_NAMEGetPaged, Line 17The multi-part identifier "dbo.NAME.MIDDLE_NAME" could not be bound.Msg 4104, Level 16, State 1, Procedure proc_NAMEGetPaged, Line 17The multi-part identifier "dbo.NAMETYPE.TYPE" could not be bound.Msg 4104, Level 16, State 1, Procedure proc_NAMEGetPaged, Line 17The multi-part identifier "dbo.FUNERAL.NUMBER" could not be bound.Msg 4104, Level 16, State 1, Procedure proc_NAMEGetPaged, Line 17The multi-part identifier "mort.NAME.CODE" could not be bound.Msg 4104, Level 16, State 1, Procedure proc_NAMEGetPaged, Line 17The multi-part identifier "NAME.LAST_NAME" could not be bound.Msg 4104, Level 16, State 1, Procedure proc_NAMEGetPaged, Line 17The multi-part identifier "NAME.FIRST_NAME" could not be bound.Msg 4104, Level 16, State 1, Procedure proc_NAMEGetPaged, Line 17The multi-part identifier "NAME.MIDDLE_NAME" could not be bound.Msg 4104, Level 16, State 1, Procedure proc_NAMEGetPaged, Line 17The multi-part identifier "NAMETYPE.TYPE" could not be bound.Msg 4104, Level 16, State 1, Procedure proc_NAMEGetPaged, Line 17The multi-part identifier "FUNERAL.NUMBER" could not be bound. </Error Messages><Sotred Procedure> CREATE PROCEDURE proc_NAMEGetPaged @startRowIndex int, @maximumRows intASBEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; SELECT NAME.CODE, NAME.LAST_NAME, NAME.FIRST_NAME + ' ' + NAME.MIDDLE_NAME AS Name, NAMETYPE.TYPE, FUNERAL.NUMBER FROM (SELECT CODE, LAST_NAME, FIRST_NAME + ' ' + MIDDLE_NAME AS Name, NAMETYPE.TYPE, FUNERAL.NUMBER, ROW_NUMBER() OVER(ORDER BY LAST_NAME) as RowNum FROM Name n) as NameInfo WHERE RowNum BETWEEN @startRowIndex AND (@startRowIndex + @maximumRows) -1ENDGO </Stored Procedure> Any assistance in resolving this would be greatly appreciated.. Regards..Peter.
View 1 Replies View RelatedIs there a way to use Row_Number without using a stored procedure? All the examples on the internet are using stored procedure.
View 10 Replies View RelatedFor some reason this query, when I include this line, does not work. But I comment it out and it works fine - do you see anything wrong that I can't see??
(Comment this out and it works)
AND RowNumber >= @RowStart
AND RowNumber <= @RowEnd
Query:
ALTER PROCEDURE [dbo].[GetNewsItemAbstracts]
-- Add the parameters for the stored procedure here
@CategoryID int,
@NewsType char(25),
-- paging
@PageSize int, @PageNumber int
AS
Declare @RowStart int
Declare @RowEnd int
if @PageNumber > 0
Begin
SET @PageNumber = @PageNumber -1
SET @RowStart = @PageSize * @PageNumber + 1;
SET @RowEnd = @RowStart + @PageSize - 1 ;
SELECT
RowNumber,[id],[headline],[publishedDate]
FROM
(SELECT [id],[headline],[publishedDate],[NewsCategoryID], [NewsType],
ROW_NUMBER() OVER(ORDER BY [publishedDate]) as RowNumber
FROM NewsItem ni
) as PagedNewsItems
WHERE
[NewsCategoryID] = @CategoryID
AND [NewsType] = @NewsType
AND RowNumber >= @RowStart
-AND RowNumber <= @RowEnd
END
Thank yoU!!
I've been using
ROW_NUMBER() OVER(ORDER BY @@langid)
in cases where row numbering is needed but order is irrelevant.
Any problems using @@langid in this way?
This is gonna be a quite long explanation of an understanding problem and I seriously hope that anyone can help me out here.
Please look at the following example:
use tempdb;
create table T1
(
C1 varchar(80) not null default 'Empty'
,C2 uniqueidentifier not null default newid()
)
go
-- Add some rows
set nocount on
insert T1(C1) values('A')
go 5
insert T1(C1) values('X')
go 7
insert T1(C1) values('Y')
go 9
insert T1(C1) values('Y')
go 6
Now run the following two queries and include the actual execution plan:
select distinct
top 10
row_number() over(order by C1), C1
from T1
select top 10
row_number() over(order by C1), C1
from T1
You€˜ll get two different plans with the first one slightly more expansive than the second.
What I do not understand is, why the optimizer does not ignore the DISTINCT in the first case. When I include a ROW_NUMBER() without partitioning (or, to e exact: with only one partition) as in the above query, every row will get a unique number, so all returned rows are already distinct, aren€™t they? But as this optimization possibility is so obvious and simple, I don€™t believe that the optimizer is wrong €“ rather I suppose that I€™m the on, who does not understand what€™s going on here.
If you play around with some SELECTs, the difference between DISTINCT included and excluded can be very noticable. Take the following example:
select distinct
top 10
row_number() over(order by a.C1), a.C1, b.C1
from T1 as a
inner join T1 as b on b.C2 = a.C2
select top 10
row_number() over(order by a.C1), a.C1, b.C1
from T1 as a
inner join T1 as b on b.C2 = a.C2
where the (unnecessary?) DISTINCT in the first query holds responsible for 34% oft he total query costs, making the cost for the first query over twice as much as for the second.
I€™ve tried to find at least one example where DISTINCT makes sense €“ but without success. In all my experiments (included the above, of course), always the same resultset is returned, regardless of DISTINCT or not.
The problem has been detected using an OR-mapper (nHibernate), where the SQL code is automatically generated. Inside the code generation process, a ROW_NUMBER() columnn without partitioning is always added, as well as in many cases also DISTINCT.
I€™d simply like to remove the DISTINCT keyword from the code generation, because it increases the performance dramatically in many cases. But fort he reasons mentioned above, I€™m not sure whether I can do this without risk.
Any ideas are greatly appreciated.
I am running a row_number fucntion but i do not have the correct sequence when i am including isnull expression, but maybe the problem is when i am trying to join the tables
my script is something like this:
SELECT TOP (100) PERCENT row_number() over( partition by a.Blasthole_Name order by a.DEPTH) as seq,
a.Blasthole_Name, a.ACTUAL_NAME, b.loaded_diameter, isnull(( select max(Z.DEPTH) from dbo.Drillability Z
where Z.Blasthole_Name = a.Blasthole_Name and Z.DEPTH < a.DEPTH), 0) as [from], a.DEPTH,
FROM dbo.Drillability a FULL OUTER JOIN
PD_Data.dbo.db_drill_hole_base b ON a.Blasthole_Name = b.drill_hole_id
GROUP BY a.Blasthole_Name, a.DEPTH, b.loaded_diameter
in shorts words i need something like this
seq Blasthole_name loaded_diameter from depth
1 dh1 12.5 0 1.2
2 dh1 12.5 1.2 2.5
3 dh1 12.5 2.5 3.7
4 dh1 12.5 3.7 4.5
5 dh1 12.5 4.5 8
6 dh1 12.5 8 12
7 dh1 12.5 12 15
1 dh2 12.5 0 1.3
2 dh2 12.5 1.3 3.6
3 dh2 12.5 3.6 5.8
4 dh2 12.5 5.8 7.3
5 dh2 12.5 7.3 8.1
6 dh2 12.5 8.1 9.3
7 dh2 12.5 9.3 11.4
8 dh2 12.5 11.4 16.4
cheers
Is there a way without rerunning the select query to get the "total row count" using
ROW_NUMBER and BETWEEN as such..
SELECT * FROM
(SELECT ROW_NUMBER() OVER(ORDER BY Year DESC, Month DESC, Day DESC) as RowNum,
e.id, e.Title
FROM Events e
) as DerivedTableName
WHERE RowNum BETWEEN @startRowIndex AND (@startRowIndex + @maximumRows) - 1
typically i would build a temp table and return SELECT @@ROWCOUNT
Hi Champs,
I am trying to either UPDATE or add a new column with ROWNUMBER() OVER an column on a table
table:
ID------Col2----Col3---
1-------12---------1
1-------34---------2
2-------44---------1
2-------75---------2
2-------77---------3
3-------23---------1
3-------33---------2
4-------44---------1
4-------22---------2
I know I can get Col3 right with an SELECT and ROWNUMBER() OVER, but how can I UPDATE the table with the result?
/Many thanks
Hi,
I'm very new to stored procedures and I've been searching on google to find a way to custom page my results using SQL Server 2005. I'm trying to use Row_Number() and a CTE to keep things efficient and scaleable but I keep getting an error next to my UPDATE statement.
I get the following error: "[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'UPDATE'."
The sproc works without the UPDATE statement. Does anyone know where I need to put the UPDATE statement to update the "searched" field for each record selected?
CREATE PROCEDURE [zk_update_request_england](@property_type tinyint,@market_status tinyint,@price int,@bedrooms tinyint,@search_location varchar(30),@search_district varchar(30),@PageSize int,@PageIndex int)
AS
BEGIN
WITH SearchResults AS(
UPDATE dbo.zk_request_england SET searched = searched + 1 WHERE property_type = @property_type AND market_status = @market_status AND bedrooms = @bedrooms AND search_location = @search_location AND search_district = @search_district AND min_price <= @price AND max_price >= @price
SELECT user_id, min_price, max_price, property_description, searched, ROW_NUMBER() OVER (ORDER BY max_price DESC) AS RowNumber FROM dbo.zk_request_england WHERE property_type = @property_type AND market_status = @market_status AND bedrooms = @bedrooms AND search_location = @search_location AND search_district = @search_district AND min_price <= @price AND max_price >= @price
)
SELECT user_id, min_price, max_price, property_description FROM SearchResults WHERE RowNumber BETWEEN (@PageIndex - 1) * @PageSize + 1 and @PageIndex*@PageSize
END
Thanks in advance for any help.
here it is:
SELECT * FROM ( SELECT ROW_NUMBER() Over (Order By LastActivity ASC) As rn UserName) FROM aspnet_usersWhere rn = 1
it's saying: "Incorrect syntax near UserName"
all column/table names are correct
I've got the following query:
WITH OrderedResults AS (SELECT some_table.*, ROW_NUMBER() OVER (ORDER BY some_field) as RowNumber FROM some_table)
SELECT TOP 10 *
FROM OrderedResults
WHERE RowNumber > 10;
which works well for returning "paginated" recordsets. But when it comes to displaying "page" links and next and previous links, I need a total count of records found... something along the lines of the MySQL CALC_FOUND_ROWS feature...
Is there some built-in MSSQL feature I can use for this, or do I have to do a SELECT count(*) FROM some_table to get this data?
Any advice is appreciated
Hi,
I would like to use an equivalent of ROW_NUMBER() T-SQL function in a SSIS package.
I could create a temporary table and use a SQL request with ROW_NUMBER() function but I would like to avoid that and generate this column in the dataflow.
Is there an easy way to do that?
Thanks,
Arnaud Gervais.
Hello,
I am wondering if somone could provide me with a sample SELECT for an
auto number query. For example I have a table called People with two columns first_name, and last_name. There isn't a unique id to correspond with the table but would like to dynamically make one during the return of the query.
I know this is possible in the full version of sql 2005 using
SELECT ROW_NUMBER() OVER (ORDER BY last_name), first_name, last_name from People
But within sql mobile is there a way?
So if there was 5 rows in the table it would return
1 John Alpha
2 John Beta
3 John Cat
4 John Delta
5 John Echo
John
Hi,
I am trying to limit a result set by ROW_NUMBER. However, I am having problems getting it working.
The following query works fine, and I get a result set with PollID, AddedDate and RowNum columns.
SELECT *, ROW_NUMBER() OVER (ORDER BY Results.AddedDate DESC) AS RowNum FROM
( SELECT DISTINCT p.PollID, p.AddedDate
FROM vw_vs_PollsWithVoteCount p
JOIN vs_PollOptions o ON p.PollID = o.PollID
) AS Results
However, as soon as I add a WHERE condition:
SELECT *, ROW_NUMBER() OVER (ORDER BY Results.AddedDate DESC) AS RowNum FROM
( SELECT DISTINCT p.PollID, p.AddedDate
FROM vw_vs_PollsWithVoteCount p
JOIN vs_PollOptions o ON p.PollID = o.PollID
) AS Results
WHERE RowNum BETWEEN 1 AND 10
The query fails with an ' Invalid column name 'RowNum' ' error.
I have tried using 'Results.RowNum' but I get the same problem.
I don't understand what the issue is. The result set has a column headed 'RowNum' so why can't I apply a WHERE clause to this column? I can apply WHERE to the PollID column, for example, with no problem.
Any help very much appreciated.
Thanks...
The row_number functions doesn't seem to be operable in our version of SQL Server 2005 SP2.
We have completely tried everything, including using the sample database, and Query posted in the 2005 SQL Server 2005 Book, which is as follows:
SELECT empid, qty,
ROW_NUMBER() OVER(ORDER BY qty) AS rownum
FROM dbo.Sales
ORDER BY qty;
I get the following error:
Msg 195, Level 15, State 10, Line 2
'ROW_NUMBER' is not a recognized function name.
Below you will find the versions of SQL we are using of 2005.
Microsoft SQL Server Management Studio 9.00.3042.00
Microsoft Analysis Services Client Tools 2005.090.3042.00
Microsoft Data Access Components (MDAC) 2000.085.1117.00 (xpsp_sp2_rtm.040803-2158)
Microsoft MSXML 2.6 3.0 4.0 5.0 6.0
Microsoft Internet Explorer 7.0.5730.11
Microsoft .NET Framework 2.0.50727.42
Operating System 5.1.2600
Please help!! Thanks in Advance,
Jason
This example is working:
Declare @startRowIndex INT; set @startRowIndex = (@PagerIndex * @ShowMembers); With BattleMembers as ( SELECT TOP 20 ROW_NUMBER() OVER (ORDER BY LastActivityDate DESC) AS Row, UserId, UserName FROM aspnet_Users) SELECT UserId, UserName FROM BattleMembers WHERE Row between @startRowIndex and @startRowIndex+@ShowMembersEND
and this one doesn't work:USE [xx]GOSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[battle_Paging]@PagerIndex INT,@ShowMembers INT ASBEGINDeclare @startRowIndex INT; set @startRowIndex = (@PagerIndex * @ShowMembers); With BattleMembers as ( SELECT TOP 20 ROW_NUMBER() OVER (ORDER BY aspnet_Users.LastActivityDate DESC) AS Row, aspnet_Users.UserId, aspnet_Users.UserName, mb_personal.Avatar FROM aspnet_Users LEFT JOIN mb_personal ON (mb_personal.UserID=aspnet_Users.UserId) SELECT UserId, UserName, Avatar FROM BattleMembers WHERE Row between @startRowIndex and @startRowIndex+@ShowMembersEND
Error:Msg 156, Level 15, State 1, Procedure battle_Paging, Line 18Incorrect syntax near the keyword 'SELECT'.
I try to join in the table mb_personal here. Some help would be very appreciated! Thanks.