Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2005

    Angry Unanswered: 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 tablethe 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.

  2. #2
    Join Date
    Feb 2004
    Dublin, Ireland
    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,
    from t a1, t a2
    where a1.bill_id >= a2.bill_id 
    group by a1.bill_id,
    order by 1
    Row_ID	bill_id	name
    1	18	def
    2	23	adfg
    3	25	abc
    4	26	ghi

  3. #3
    Join Date
    Sep 2005
    Thanks a really WORKED....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts