use DB1
go
--变量定义我就不写了,
declare R_x cursor
for select code,[name],description2,description3,description5,description6 from dbo.Material_Syn  Order by id
open R_x
fetch next from R_x into @Code,@Name,@description2,@description3,@description5,@description6
---在这里我想连到db2中取一个值。
use db2  问题就出在这里,@baseid取到值,我感觉从这里往下就没运行过,不知道是不是游标内部不能使用use db
SELECT @baseid=material  from dbo.proc_materials  where materialtype=32

while @@fetch_status=0
begin
------这里面有一些update操作
endfetch next from R_x into @Code,@Name,@description2,@description3,@description5,@description6 --回过头再取一便
Close R_x
DEALLOCATE R_x