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!

Row number in the SQL Query 1

Status
Not open for further replies.

ishwarjindal

Programmer
Nov 10, 2002
9
IN
I have a requirement in SQL Query that i need a unique number along with each row returned by the SQL Query.

It doesn't matter whether i am using single table or multiple tables.

Note : I have a soultion of this problem but it need the creation of a table
(i.e. using Select IDENTITY(int,1,1) as ROWID , t1.* INTO t2 from t1). I want a better solution which shouldn't involve the craetion of new table
 
Why not use a temporary table with the correct fields (including the identity field). Temporary tables can be created by all users

then insert the data
then select the data
then drop the temporary table

Can all be done in one sql script/sp

Andy


e.g.-----------

set nocount on


create Table ##PieData (Description varchar(255) , PieData int)

insert into ##piedata
select top 5 ClientName+'-'+product, estimatedrevenue
from ET_REP_vw_Pie_Chart_Data
where countrydescription like @country
order by estimatedrevenue desc

set nocount off

--now simply select everything from the temporary table created

select *

from ##piedata order by piedata desc

--lastly drop table

drop table ##PieData
 
There is an FAQ on this with some good suggestions:

faq183-3021 --James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top