If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > Auto increment column in select query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-18-11, 02:08
agrawal.meet agrawal.meet is offline
Registered User
 
Join Date: Jun 2010
Posts: 51
Auto increment column in select query

Hello Experts,

This question has forever eluded me. So posting here.

How can we generate a unique number for every row returned.

for example:

Code:
Select id = identity(10), Name, Address
from Table1
Above query gives you syntax error saying you can only generate id if you are actually inserting into a table and not in the select statement.

I know this is possible in Oracle but is this even possible in Sybase ASE 12.5?

Hope the question is clear.

Thanks,
Meet
__________________
Please always reply to the post if it was helpful. Others may find it helpful.
Reply With Quote
  #2 (permalink)  
Old 01-18-11, 03:09
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
No, you'll have to insert into a temp table then select from the temp table
Code:
Select id = identity(10), Name, Address
into #t1
from Table1
select * from #t1
drop table #t1
Reply With Quote
  #3 (permalink)  
Old 01-18-11, 03:15
agrawal.meet agrawal.meet is offline
Registered User
 
Join Date: Jun 2010
Posts: 51
That's exactly my question. This means that this is not possible in sybase ASE? You have to insert into a temp table first?
__________________
Please always reply to the post if it was helpful. Others may find it helpful.
Reply With Quote
  #4 (permalink)  
Old 01-19-11, 02:35
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
Yes, you have to insert into a temp table first.
If your table isn't large and you have a unique key then you can generate it with a self join.
Provide some sample data if you want an example.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On