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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable increment in select statement

Status
Not open for further replies.
Dec 13, 2002
109
GB
Im trying to increment a variable in a select statement
such as

declare @cnt as int

select field1, field2,(select @cnt = @cnt + 1)
from A_TABLE

but Im getting an "incorrect syntax error near =" message. Ive tried various combinations to no avail. Is this possible?
 
Code:
SELECT
(SELECT COUNT (*) FROM A_TABLE A
WHERE A.FIELD1 <= B.FIELD1) INCREMENT, *
FROM A_TABLE B
ORDER BY INCREMENT

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
Try this:

How Do I Get a Row Number On Each Row of a Query Result Set?
faq183-3021

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top