Türkçe
|
English
Blog
|
News
|
Articles
|
Links
|
Blogroll
|
Files
|
Photos
|
Contact
|
Who Is
Calendar
<
November 2008
>
Pt
Sa
Ça
Pe
Cu
Ct
Pz
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
Search
Categories
Clues (10)
Codes (10)
Funny (2)
News (16)
Open Source (3)
Show All
Archive
November,2008 (1)
September,2008 (1)
August,2008 (1)
June,2008 (3)
May,2008 (1)
April,2008 (5)
March,2008 (1)
February,2008 (1)
January,2008 (9)
November,2007 (1)
April,2006 (2)
Show All
Links
Chameleon
My Yazgelistir Articles
Palantir
Yazgelistir
Show All
Blogroll
Behlül Behram
Berke Sökhan
Işıl Orhanel
Mehmet Emre
Ozan Günceler
Show All
Files
Random Number Generators
Show All
Dynamic Top N Query
-
10.01.2008
We use TOP N sql command to show top results of a sql query. However we can't use N as dynamic or parametric in TOP N command like getting value of N from a parameter table or from a parameter of a stored procedure. We can use SET ROWCOUNT command for this purpose. Syntax of this command is SET ROWCOUNT N where n is the count of rows to return where 0 means all rows will be returned. You have to set set rowcount to 0 after executing a command in order not to following queries return top n records.
DECLARE
@rowCount
int
SET
@rowCount
=
(
SELECT
ParameterValue
FROM
Parameters
WHERE
ParameterId
=
12
)
SET
ROWCOUNT
@rowCount
SELECT
*
FROM
MyTable
ORDER
BY
MyColumn
SET
ROWCOUNT
0
GO
CREATE
PROC
MyQuery
@rowCount
int
AS
SET
ROWCOUNT
@rowCount
SELECT
*
FROM
MyTable
ORDER
BY
MyColumn
SET
ROWCOUNT
0
GO
Clues,Codes
Add Comment
First Name Last Name
Web Site
E-Mail
Comment
Security Picture
Photos
A break for traditional American Breakfast
Show All
Entries
Encrypting The Web.Config
Summary Of Last 2 Months
Most Valuable Practices On The Way To Solution
Yazgelistir - CodeSnippets And Open Source Projects
Announcment From Microsoft: SharePoint Developer Introduction for .NET Developers launched
Internet Explorer 8 Beta 2 Coming in August
T.C. Identity Number correctness validation
My USA Diary - New York
My USA Diary - Seattle
My USA Diary - Chicago
Show All
News
Show All
Articles
Chameleon - Connection Settings Manager
MathParser - Math Formula Parser
Show All