1

I am using a stored procedure to make page-navigation when I view a list of stores. I have only one table Store with columns Name & S_Id.

And here is my query :

    SELECT  Stores.Name
    FROM
       (
         SELECT ROW_NUMBER() OVER (ORDER BY Stores.S_Id) AS rownum ,
            Stores.Name
         FROM Stores    
       )AS ordered
    WHERE ordered.rownum BETWEEN [someValue] AND [someValue] 

But when I try to save my procedure I get an error:

can not bind a composite identifier Stores.Name

I have seen a lot of topics but cant find whats wrong. If I doing it with LINQ I will try something like this :

    (select name from Stores order by S_Id).Skip(n).Take(m) .
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Anton Putov
  • 1,951
  • 8
  • 34
  • 62

1 Answers1

1

Your subquery defines a new name - ordered - for your data - so you need to use that new name instead of stores:

SELECT  
    ordered.Name    <=== you're selecting from the subquery which is called "ordered" - use that name!!
FROM
   (SELECT 
       ROW_NUMBER() OVER (ORDER BY Stores.S_Id) AS rownum,
       Stores.Name
    FROM Stores    
   ) AS ordered
WHERE 
   ordered.rownum BETWEEN [someValue] AND [someValue] 
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459