| Author |
Topic |
|
oracle_corrgi
Yak Posting Veteran
98 Posts |
Posted - 2007-01-30 : 00:31:50
|
| hiif i need to get only the top 75 i give select top 75 columnname from tablename in my procnow i need to declare input the select according to me say 15 40 68 any number in the procdeclare@top intselect @top tpa_id,empe_key,* from dbo.[dept]krmm |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-30 : 00:37:02
|
| set rowcount @rowsselect * from dbo.[dept] order by somecolset rowcount 0Peter LarssonHelsingborg, Sweden |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-01-30 : 00:40:53
|
use set rowcountuse pubsdeclare @rows intselect @rows = 10set rowcount @rowsselect * from salesselect @rows = 20set rowcount @rowsselect * from sales-- remember to set back to 0 for allset rowcount 0 KH |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-01-30 : 00:42:08
|
Got distracted by . . . KH |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-30 : 00:44:26
|
| If using SQL Server 2005,SELECT TOP (@Rows) * FROM MyTable ORDER BY SomeColPeter LarssonHelsingborg, Sweden |
 |
|
|
oracle_corrgi
Yak Posting Veteran
98 Posts |
Posted - 2007-01-30 : 01:11:40
|
| dont u have in sqlserver 2000 SELECT TOP (@Rows) * FROM MyTable ORDER BY SomeColdeclare @rows intset rowcount @rowsselect * from salesthat give me errorServer: Msg 507, Level 16, State 2, Line 2Invalid argument for SET ROWCOUNT. Must be a non-null non-negative integer.i need to get only the supplied number from the parmeterkrmm |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2007-01-30 : 01:20:38
|
| You got an error because you didn't supply a value for @rows.CODO ERGO SUM |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-30 : 01:20:43
|
The error message is self-explained!The @rows variable should be the parameter you talked about in the original posting.If you want to test first, set @rows to a value of your choice!declare @rows intset @rows = 10set rowcount @rowsselect * from sales Once again, when given suggestions and you don't understand them, please read about the specific command or statement in Books Online.Peter LarssonHelsingborg, Sweden |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-01-30 : 01:21:58
|
quote: dont u have in sqlserver 2000 SELECT TOP (@Rows) * FROM MyTable ORDER BY SomeCol
Not in SQL Server 2000.declare @rows int-- you did not initialize the @rowsselect @rows = 10set rowcount @rowsselect * from salesset rowcount 0 KH |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-01-30 : 01:26:06
|
againAnd weird also. Similar modification, Same color coding  KH |
 |
|
|
oracle_corrgi
Yak Posting Veteran
98 Posts |
Posted - 2007-01-30 : 01:26:12
|
| in my select statment i dont need to send the row=10 if that is the case if i need 75 then i need to put row=75 is that i will be send the ro count from the applicationbascically i need to select the rowcount and insert into temp table say 20 30 15 differ'skrmm |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-30 : 01:29:09
|
| If always selecting 75 first rows, SELECT TOP 75 * FROM Sales ORDER BY {SomeCol}But this is NOT what you requested in the original posting...Peter LarssonHelsingborg, Sweden |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-01-30 : 01:32:03
|
quote: now i need to declare input the select according to me say 15 40 68 any number in the proc
Pass the required rows number 15, 40 or 68 into the variable @rows KH |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-30 : 01:33:13
|
| [code]CREATE PROCEDURE uspGetMySales( @NumRows INT = 10)ASSET NOCOUNT ONIF @NumRows IS NULL SELECT @NumRows = 10SET ROWCOUNT @NumRowsSELECT *FROM SalesORDER BY {SomeCol} DESCSET ROWCOUNT 0[/code]Now this stored procedure accepts a parameter. Send a value from your application how many rows you want to be returned.If no value is sent, or NULL is sent, the procedure defaults to 10 rows.Peter LarssonHelsingborg, Sweden |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
|