Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Autonumber in a return select statement
Message
 
 
À
25/09/2003 14:54:28
Alvin Lourdes
Children and Youth Services Cluster
Toronto, Ontario, Canada
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00832412
Message ID:
00832546
Vues:
26
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--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform