dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: SQL Server
Expertise: Beginner
Sep 18, 1998

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Displaying the Row Number in a SELECT Query

Question:
How can I display the row number in the results of a SELECT query? For example:
 
Select empname 
from employees 
where city = "toronto"
I would like to show the row number as follows:
 
  1 Fred
  2 Bill
  3 Jeff
  4 June

Answer:
You are probably better off handling such formatting issues in your front-end. In T-SQL, you would first have to build a table that mimics what your result set looks like with the addition of an identity column:

 
create table #result
(
   id int identity(1,1),
   empname char(20)
)
Then insert your result set into the temporary table. Lastly, select out of the temporary result set.

I think you can see why a front-end should be able to handle this more easily.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date