【发布时间】:2015-08-13 10:04:11
【问题描述】:
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
这是查询。 '@qry' 被我们传递给查询的内容所改变
【问题讨论】:
-
对不起,我看不懂。
-
参见 [SQL “if exists...” 动态查询][1] 或 [TSQL - Trying to use variable with IF EXISTS() Function for simple SP][2] [1]: stackoverflow.com/questions/27710260/… [2]:stackoverflow.com/questions/14073842/…