| Author |
Topic |
|
CLages
Posting Yak Master
116 Posts |
Posted - 2005-11-19 : 06:29:29
|
| Hi, i have been searching but i find nothing.i have one table cod name 123 aaaa124 bbbb125 xxxxetc when in QA i get using select cod name 1 123 aaaa2 124 bbbb3 125 xxxxHow can i get the Row Number ?i would like to get 2 if i Select * from table where cod = 124 tksClagesBy the way in this case i can not use Identity column |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-11-19 : 06:49:53
|
select * from(select identity(int, 1, 1) as rownum, *from yourTable) twhere cod = 124Go with the flow & have fun! Else fight the flow |
 |
|
|
CLages
Posting Yak Master
116 Posts |
Posted - 2005-11-19 : 07:36:11
|
| SORRY , I GET THIS ERRORIncorrect syntax near the keyword 'identity'AS I SAID I HAVE NO IDENTITY COLUMN IS THIS TABLETKScLAGES |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-19 : 07:41:33
|
Select rowNum from ( select (select count(*) from yourTable where cod<=T.cod) as RowNum, cod from yourTable T ) Twhere cod=124 MadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-19 : 07:46:09
|
quote: Originally posted by spirit1 select * from(select identity(int, 1, 1) as rownum, *from yourTable) twhere cod = 124Go with the flow & have fun! Else fight the flow 
Select identity(int,1,1) from ..... wont work I think you meant thisSelect identity(int,1,1) as rowNum, cod into #t from yourTableSelect rowNum from #t where cod=124Drop table #tMadhivananFailing to plan is Planning to fail |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-11-19 : 07:49:33
|
yeah... next time remind me not to answer questions after sleeping only 4 hours... Go with the flow & have fun! Else fight the flow |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-19 : 08:14:46
|
quote: Originally posted by spirit1 yeah... next time remind me not to answer questions after sleeping only 4 hours... Go with the flow & have fun! Else fight the flow 
So you are very busy? MadhivananFailing to plan is Planning to fail |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-11-19 : 10:20:21
|
no not really... it was friday night out... went to sleep at 6 am Go with the flow & have fun! Else fight the flow |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2005-11-21 : 06:52:35
|
How about reminding you not to answer questions that have no meaning? You want row numbers, use Excel. Help us help YOU!Read this blog entry for more details: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx*need more coffee*SELECT * FROM Users WHERE CLUE > 0(0 row(s) affected) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-21 : 06:59:35
|
orUse an identity column MadhivananFailing to plan is Planning to fail |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-11-21 : 07:55:11
|
sure Don... that would work too... Go with the flow & have fun! Else fight the flow |
 |
|
|
CLages
Posting Yak Master
116 Posts |
Posted - 2005-11-21 : 08:44:17
|
| When i Asked how to get a row number, of couse i have a reason to usethis.The reasom is to create a Specific table getting values of several tables, But this new table can not have identity column, because the column that will get this values is Char(10).In other wordsthe New table has this columnsCode(char(10) LoteNumber(char(10) (both are key)loteNumber should be a combination of Columns (string Of course)but in same case I have Duplicate Key, then i think , ifadd the RowNumber is this combination of columns , i will never getDuplicate Key.tksAnywayClages |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
|
|
|