Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > offset in Select top N documents View modes: 
User avatar
Member
Member
support-schepnet - 6/3/2009 9:29:42 AM
   
offset in Select top N documents
Is it possible to set a repeater to show a offset for the available document types?

For instance, I want to show six events, but starting from the second one, because the first one is shown by another webpart on the same page.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 6/4/2009 5:05:22 AM
   
RE:offset in Select top N documents
Hi,

You need to create a WHERE condition for the repeater. It will be combined where condition where you will use also a select statement. Here you will select the TOP 1 document from the documents type table. So, it could look like this:

WHERE: DocumentID NOT IN (SELECT TOP 1 FROM Table)

I hope it will help.

Best Regards,
Juraj Ondrus

User avatar
Member
Member
merete-grape - 2/16/2012 5:43:57 AM
   
RE:offset in Select top N documents
need to split news into 2 on my page.

one with detail, and the list without detail.

Tryed to type in; NewsID NOT IN (SELECT TOP 1 FROM CONTENT_news)
in the WHERE condition...

this fails
(I use v5.5.3996 R2 )

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 2/18/2012 10:35:10 PM
   
RE:offset in Select top N documents
Hi,

In previous sample is a little bit mistake, I missed the column name. In your case, the WHERE condition should look like this:

NewsID NOT IN (SELECT TOP 1 NewsID FROM CONTENT_news)

Anyway, you can check what error is being logged in the Site Manager -> Administration -> Event log to see more details - in general if you are having any issues.

Best regards,
Juraj Ondrus

User avatar
Member
Member
merete-grape - 3/6/2012 4:29:00 AM
   
RE:offset in Select top N documents
Sorry for late feedback.

Used this:
NewsID NOT IN (SELECT TOP 1 NewsID FROM CONTENT_news)

still shows all news.... from no. 1-5 not like I want... no. 2-6

No error is being logged....

(HG Gokstad)
news-list in left column and no. 1 news in middle

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 3/6/2012 7:06:01 AM
   
RE:offset in Select top N documents
Hi,

I think I got it and you forgot to mention one important thing - are you using multiple sites within the same CMS?

If so, the above where condition is applied across all news from all sites - so the IDs won't match. You need to use something like this:

NewsID NOT IN
(SELECT TOP 1 NewsID FROM View_CONTENT_News_Joined WHERE NodeSiteID = <ID of your site>)


Best regards,
Juraj Ondrus

User avatar
Member
Member
andrewmacpherson - 5/31/2012 8:55:28 AM
   
RE:offset in Select top N documents
I spent some time wrestling with this issue too. I eventually realized that the WHERE clause on the nested SELECT TOP 1 requires ALL of the same WHERE conditions as the outer SELECT. It also needs the same ORDER BY.

I managed to get an off-set to work by using a "Repeater with Custom Query" web part. First, define a custom query for your document type. Here's my example, which I called "selectDocumentsWithOffset1". As you can see, the WHERE and ORDER BY is used in both the outer and inner SELECT statements.


SELECT ##TOPN## ##COLUMNS##
FROM View_CONTENT_News_Joined -- DOCUMENT TYPE hardcoded, use the correct database view
WHERE( ##WHERE## )
AND ( NodeID NOT IN (
SELECT TOP 1 -- OFFSET hardcoded
NodeID
FROM View_CONTENT_News_Joined -- DOCUMENT TYPE hardcoded, use the correct database view
WHERE ( ##WHERE## )
ORDER BY ##ORDERBY##
)
)
ORDER BY ##ORDERBY##


Notes:
1. You will need to edit this custom query to use your own document type and offset count.
2. I used NodeID rather than NewsItemID, to avoid the NodeSiteID problem described by Juraj.

If you're trying to do this with a regular CMS repeater web part, it's quite likely that you're passing in other conditions like path, published, etc.

Unlike a regular CMSRepeater, a QueryRepeater doesn't offer options for published, path, maxRelativeLevel, etc., so you'll need to provide these yourself in the QueryRepeater's Where condition. Here's an example - it's similar to the SQL which CMSRepeater generates internally from its properties:


(SiteName = N'MySite')
AND
(Published = 1)
AND
(DocumentCulture = N'en-GB')
AND
(NodeAliasPath LIKE N'/latest-news/%')
AND
(NodeLevel <= 2)



User avatar
Member
Member
merete-grape - 6/5/2012 5:11:40 PM
   
RE:offset in Select top N documents
Think this is good too:
(Placed in WHERE condition:)

NewsID NOT IN (Select TOP 1 NewsID from View_CONTENT_news_Joined where NodeSiteID = 26 ORDER BY NewsReleaseDate DESC)