Friday, March 30, 2012

Query help

For reasons i wont go into i need to have an identity field when returning a
select statement
ie Select * from Table1 returnn
Field1 field2 etc
aa aa aa
bb bb bb
and i want
Field1 field2 etc IDENT
aa aa aa 0
bb bb bb 1
any clues ?Assuming that you PK is field1 and the order of Id cols is also based on Fie
ld1
select
t1.*,
(select count(*) from table1 t2 where t2.Field1 < t1.Field1) as IdCol
from Table1 t1
- Sha Anand
"Peter Newman" wrote:

> For reasons i wont go into i need to have an identity field when returning
a
> select statement
> ie Select * from Table1 returnn
> Field1 field2 etc
> aa aa aa
> bb bb bb
> and i want
> Field1 field2 etc IDENT
> aa aa aa 0
> bb bb bb 1
> any clues ?|||How to dynamically number rows in a SELECT Transact-SQL statement
http://support.microsoft.com/defaul...kb;en-us;186133
AMB
"Peter Newman" wrote:

> For reasons i wont go into i need to have an identity field when returning
a
> select statement
> ie Select * from Table1 returnn
> Field1 field2 etc
> aa aa aa
> bb bb bb
> and i want
> Field1 field2 etc IDENT
> aa aa aa 0
> bb bb bb 1
> any clues ?

No comments:

Post a Comment