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

abc666 2004-02-13 04:23:39
问题行要怎么写才能运行?
我试过下面几种写法,都不行:

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
...全文
22 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧