我的动态语句怎么才能运行?

abc666 abc666 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
问题行要怎么写才能运行?
我试过下面几种写法,都不行:

if exists (@str1)
if exists (exec @str1)
if exists (exec sp_executesql @str1)




declare @fisyear varchar(4)
declare @str1 varchar(300)
declare @t table (msg nvarchar(100))

set @fisyear='2003'

set @str1 = 'select distinct ts_office from cpm_timesheet where ts_fisyear='''+@fisyear+''' and ts_office not in (select distinct mf_office from cpm_MF where mf_fisyear='''+@fisyear+''')'
select @str1
if exists (@str1) <--问题行
begin
declare @err_mf cursor for @str1
open @err_mf
fetch next from @err_mf into @err_office
while @@fetch_status=0
begin
insert into @t values (@err_office+N'办公室 '+@fisyear+N'财政年度 没有办公室倍率')
fetch next from @err_mf into @err_office
end
end
select * from @t
...全文
评论 8
收藏 已收藏
分享
返回顶部
abc666
疑难问题 22,298 成员 121,727 内容