Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Bex
Aged Yak Warrior
580 Posts |
Posted - 2009-04-02 : 06:29:45
|
| Hi thereI have a table that contains a load of records. I want to select only the MAX(TranID) from the TOP (@x) amount. I created the following query:SELECT @TransactionID = MAX(tranid) FROM dbo.testwhere ROW_NUMBER() OVER (ORDER BY tranid) <= @BatchSizeBut I get the error:Msg 4108, Level 15, State 1, Procedure DeleteFromTest, Line 14Windowed functions can only appear in the SELECT or ORDER BY clauses.How else can I model the query to get the same results?ThanksHearty head pats |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-02 : 06:35:34
|
| Select @TransactionID = MAX(tranid) from(SELECT tranid,ROW_NUMBER() OVER (ORDER BY tranid) as Sno FROM dbo.test) as t where Sno<= @BatchSizeMadhivananFailing to plan is Planning to fail |
 |
|
|
Bex
Aged Yak Warrior
580 Posts |
Posted - 2009-04-02 : 06:47:05
|
| Thanks mate. That works perfectly!Hearty head pats |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-02 : 08:17:35
|
quote: Originally posted by Bex Thanks mate. That works perfectly!Hearty head pats
You are welcome MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|