<cfquery name="qID" datasource="...">
SELECT
b.id
FROM
blog_entry b
INNER JOIN
display_status d
ON
(
b.display_status_id = d.id
AND
d.is_active = 1
AND
d.is_listed = 1
<cfif REQUEST.Attributes.search_year>
AND
b.date_posted >= <cfqueryparam value="#CreateDate(REQUEST.Attributes.search_year, 1, 1)#" cfsqltype="CF_SQL_TIMESTAMP" />
AND
b.date_posted < <cfqueryparam value="#CreateDate((REQUEST.Attributes.search_year + 1), 1, 1)#" cfsqltype="CF_SQL_TIMESTAMP" />
</cfif>
<cfif (REQUEST.Attributes.search_year AND REQUEST.Attributes.search_month)>
AND
b.date_posted >= <cfqueryparam value="#CreateDate(REQUEST.Attributes.search_year, REQUEST.Attributes.search_month, 1)#" cfsqltype="CF_SQL_TIMESTAMP" />
AND
b.date_posted < <cfqueryparam value="#DateAdd('m', 1, CreateDate(REQUEST.Attributes.search_year, REQUEST.Attributes.search_month, 1))#" cfsqltype="CF_SQL_TIMESTAMP" />
</cfif>
<cfif REQUEST.Attributes.search_tag_id>
AND
b.id IN
(
SELECT
btjn.blog_entry_id
FROM
blog_entry_tag_jn btjn
WHERE
btjn.tag_id = <cfqueryparam value="#REQUEST.Attributes.search_tag_id#" cfsqltype="CF_SQL_INTEGER" />
)
</cfif>
)
ORDER BY
b.date_posted DESC,
b.time_posted DESC,
b.id DESC
</cfquery>