读书人

使用execute()出,该怎么处理

发布时间: 2012-01-19 00:22:28 作者: rapoo

使用execute()出
我在SQL SERVER2000 的查分析器上用execute出:

declare @_tmp varchar(8000),@_id_code varchar(230)
select @_id_code= 'aaa '

SELECT @_tmp= 'insert into sod_tmp(sod_id,sol_id,soh_id) '
+ ' SELECT thisid,line_id,header_id from sod_planned_unreleased_v '
+ ' WHERE sol_orgid=1 and soh_orgid=1 AND soh_entry_status_code not in (select code_string from sod_tmp2 where id_code=@_id_code) '
execute(@_tmp)

如下:

Server: Msg 137, Level 15, State 2, Line 1
Must declare the variable '@_id_code '.

我@_id_code明明已declare 了,啥出,各位兄弟,指一下,怎做才



[解决办法]
declare @_tmp nvarchar(4000),@_id_code varchar(230)
select @_id_code= 'aaa '

SELECT @_tmp= 'insert into sod_tmp(sod_id,sol_id,soh_id) '
+ ' SELECT thisid,line_id,header_id from sod_planned_unreleased_v '
+ ' WHERE sol_orgid=1 and soh_orgid=1 AND soh_entry_status_code not in (select code_string from sod_tmp2 where id_code=@_id_code) '

execute sp_executesql @_tmp,N '@_id_code varchar(230) input ',@_id_code input
[解决办法]
declare @_tmp varchar(8000),@_id_code varchar(230)
select @_id_code= 'aaa '

SELECT @_tmp= 'insert into sod_tmp(sod_id,sol_id,soh_id) '
+ ' SELECT thisid,line_id,header_id from sod_planned_unreleased_v '
+ ' WHERE sol_orgid=1 and soh_orgid=1 AND soh_entry_status_code not in (select code_string from sod_tmp2 where id_code= ' ' '+@_id_code+ ' ' ') '
exec(@_tmp)

[解决办法]

declare @_tmp varchar(8000),@_id_code varchar(230)
select @_id_code= 'aaa '
句一起放入@_tmp中吧

读书人网 >SQL Server

热点推荐