declare @qry varchar(100)
declare @cnt int
set @qry = ' where '
if exists( select * from ARTICLE_MANAGE +@qry+ article_id=65)
BEGIN
select top 1* from ARTICLE_MANAGE order by article_id desc
END
ELSE
BEGIN
select * from ARTICLE_MANAGE order by article_id desc
END
This is the query. '@qry' is changed by what we passed to the query
Here you are building a
dynamic sql
andEXISTS
limits to onlysubquery
.You can have the functionality of
EXISTS
withcount(*)