Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Autonumber in a return select statement
Message
 
 
To
25/09/2003 14:54:28
Alvin Lourdes
Children and Youth Services Cluster
Toronto, Ontario, Canada
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00832412
Message ID:
00832546
Views:
25
This message has been marked as the solution to the initial question of the thread.
>Hi,
>I want to be able to return an autonumber 1,2,3 for each row returned in my select statement.
>
Hi Alvin,

Here's a sample code that shows how it can be done using temporary table.
USE Northwind
SELECT CAST(0 AS int) AS sqn, * 
	INTO #temp01
	FROM dbo.Orders
DECLARE @sq int
SET @sq = 0
UPDATE #temp01 SET @sq=@sq+1, sqn=@sq
SELECT * FROM #temp01
DROP TABLE #temp01

-- or if there's no identity column in the result set
USE Northwind
SELECT IDENTITY(int, 1,1) AS sqn, * 
	INTO #temp01
	FROM Customers
SELECT * FROM #temp01
DROP TABLE #temp01
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform