Showing posts with label whenever. Show all posts
Showing posts with label whenever. Show all posts

Monday, March 26, 2012

row_id in sql server....

Hi all,
i have a task that whenever i will write a select query then when the result comes then i should be able to write a column that should write the ROW-ID of these rows. I mean for example i write a select query that gives me the following table:(the query can be like select bill_id,name from myTable order by name)
Bill_id name
25 abc
18 def
26 ghi
23 adfd

but my result should look like:
Row_Id Bill_id name
1 25 abc
2 18 def
3 26 ghi
4 23 adfd

n this Row_Id should be generated automatically...even if when i will write order by name in reverse order then also it should write the row_id as 1,2,3,4 same increasing order...n this automatic function i have to make...i cant understand..if there exist some procedure or function that already does this...or how can i just find the simple ROW_ID in general???
any help will be greatly appreciated.
Regards.create table t(bill_id int, name varchar(10))

insert into t values(25, 'abc')
insert into t values(18, 'def')
insert into t values(26, 'ghi')
insert into t values(23, 'adfg')

select Row_ID=count(*), a1.bill_id, a1.name
from t a1, t a2
where a1.bill_id >= a2.bill_id
group by a1.bill_id, a1.name
order by 1

Row_ID bill_id name
-------
1 18 def
2 23 adfg
3 25 abc
4 26 ghi|||Thanks a lot...it really WORKED...
regards.sql

Monday, March 12, 2012

Row id in sql server....

Hi all,
i have a task that whenever i will write a select query then when the result comes then i should be able to write a column that should write the ROW-ID of these rows. I mean for example i write a select query that gives me the following table:(the query can be like select bill_id,name from myTable order by name)

Bill_id

name

25

abc

18

def

26

ghi

23

adfd


but my result should look like:

Row_Id

Bill_id

name

1

25

abc

2

18

def

3

26

ghi

4

23

adfd

n this Row_Id should be generated automatically....even if when i will write order by name in reverse order then also it should write the row_id as 1,2,3,4 same increasing order...n this automatic function i have to make...i cant understand..if there exist some procedure or function that already does this...or how can i just find the simple ROW_ID in general?
any help will be greatly appreciated.
Regards.ok,i found the solution....here it is:

select rank=count(*), a1.au_lname, a1.au_fname
from authors a1, authors a2
where a1.au_lname + a1.au_fname >= a2.au_lname + a2.au_fname
group by a1.au_lname, a1.au_fname
order by 1
|||http://www.aspfaq.com/2427
wrote in message

news:4cd06c7a-358b-47eb-943e-e4e74d2d52b8@.discussions.microsoft.com...

> Hi all,

> i have a task that whenever i will write a select query then when the

> result comes then i should be able to write a column that should write

> the ROW-ID of these rows. I mean for example i write a select query that

> gives me the following table:(the query can be like select bill_id,name

> from myTable order by name)

>

> Bill_id

>

> name

>

> 25

>

> abc

>

> 18

>

> def

>

> 26

>

> ghi

>

> 23

>

> adfd

>

>

> but my result should look like:

>

> Row_Id

>

> Bill_id

>

> name

>

> 1

>

> 25

>

> abc

>

> 2

>

> 18

>

> def

>

> 3

>

> 26

>

> ghi

>

> 4

>

> 23

>

> adfd

>

> n this Row_Id should be generated automatically....even if when i will

> write order by name in reverse order then also it should write the

> row_id as 1,2,3,4 same increasing order...n this automatic function i

> have to make...i cant understand..if there exist some procedure or

> function that already does this...or how can i just find the simple

> ROW_ID in general?

> any help will be greatly appreciated.

> Regards.

>

>