Oh Baby, It's So Hot When You Paginate! (aka Paginating Results In ColdFusion)

<!--- Query for blog entries. --->
<cfquery name="REQUEST.EntryQuery" datasource="...">
	SELECT
		b.id,
		b.name,
		b.date_posted,
		b.time_posted,
		b.description,
		b.content,
		(
			SELECT
				COUNT(*)
			FROM
				blog_comment c
			WHERE
				c.blog_entry_id = b.id
		) AS comment_count,
		d.is_viewable
	FROM
		blog_entry b
	INNER JOIN
		display_status d
	ON
		(
				b.display_status_id = d.id
			AND
				(
						1 = 0
 
					<!--- Check for IDs. --->
					<cfif qID.RecordCount>
 
						<cfloop index="intRow" from="#REQUEST.Pager.GetStart()#" to="#REQUEST.Pager.GetEnd()#" step="1">
							OR
								b.id = <cfqueryparam value="#qID[ 'id' ][ intRow ]#" cfsqltype="CF_SQL_INTEGER" />
						</cfloop>
 
					</cfif>
 
				)
		)
 
	<!--- Check for IDs. --->
	<cfif qID.RecordCount>
 
		ORDER BY
			(
				CASE
					<cfloop index="intRow" from="#REQUEST.Pager.GetStart()#" to="#REQUEST.Pager.GetEnd()#" step="1">
						WHEN
						b.id = <cfqueryparam value="#qID[ 'id' ][ intRow ]#" cfsqltype="CF_SQL_INTEGER" />
						THEN
							<cfqueryparam value="#intRow#" cfsqltype="CF_SQL_INTEGER" />
					</cfloop>
					ELSE
						0
				END
			) ASC
 
	</cfif>
</cfquery>

For Cut-and-Paste