Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating a query with row numbers

Status
Not open for further replies.

slames

Technical User
Nov 5, 2002
211
GB
Hi, I'm trying to add row numbers to a query so I can iterate through them easily in a loop. I have done it before in an Access query but now need to recreate this in a sql server stored procedure - this is the syntax I am using :

Alter Procedure spItemsToBillNum

As

SELECT (select count (*) from spItemsToBill as E2 where E2.jbID < E1.jbid)+1 AS itbrownum, *
FROM spItemsToBill AS e1
ORDER BY e1.jbID;

But this returns the error

Invalid object name spItemsToBill - this shouldn't be the case as it is definately an object.

Can anyone help on this one?

Thanks

Steph

 
I have just copied the sql from the stored procedure into a view - this query now works, forgive me for not being very knowledgable on the subject but what is the reason for this?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top