Y_L_Y_L 2017-08-07 03:42 采纳率: 87.5%
浏览 831
已采纳

求SQL大神帮忙解决问题!!!!!

这段SQL就是要查出某一个ID值在数据库全局的使用情况,然后用新的ID替换掉原来的数据。
但是会一直报错,如图,求解!如果有更好的写法更好!

 declare @str varchar(100)
set @str='3a28c205-df29-40b0-b246-74fd8aa70a12';
declare @tablea table(name sysname, status tinyint, xusertype smallint, id int)
insert into @tablea   
select name,status,xusertype,id from syscolumns;
declare @tableb table(name sysname, xtype char(2), id int)
insert into @tableb   
select name,xtype,id from sysobjects;
declare @tableNmae varchar(100);
declare @columnName varchar(100);
declare @query varchar(8000);
declare @updateSql varchar(8000)
declare curs cursor local for

    select query = 'if exists(select 1 from ['+b.name+'] where ['+a.name+'] like ''%'+@str+'%'') print ''所在的表及字段: ['+b.name+'].['+a.name+']'''  
    from @tablea a join @tableb b on a.id=b.id
    where b.xtype='U' and a.status>=0 and a.xusertype in(175,239,231,167) ;
    select @tableNmae = name from @tableb ;
    select @columnName = name from @tablea;
    select @updateSql = 'UPDATE '+@tableNmae+ ' SET '+ @columnName+' = LOWER(NEWID()) WHERE  '+ @columnName+ 'like ''%'+ @str +'%'''
open curs

fetch next from curs into @query
while @@fetch_status=0 begin
    exec(@query)    

        exec(@updateSql)

fetch next from curs into @query
end
close curs
deallocate curs

图片:
图片说明

  • 写回答

5条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 Maya的Fbx模型导入Ue4.24后为什么个别部位的UV发生了改变?
      • ¥15 网页设计与开发html
      • ¥15 bin格式的程序文件烧录GD32F105芯片。起始地址填多少?
      • ¥15 python对txt文件的处理
      • ¥25 需要一个能在H5中实现扫码的插件
      • ¥50 ArcGIS或MATLAB实现批量计算整个tif图像的EVI
      • ¥20 两个板子之间CAN通信ID号怎么设置
      • ¥15 两个板子CAN通信的话ID号怎么设置
      • ¥15 vue使用element-ui的el-upload上传图片至服务器,服务端使用的是node.js,图片上传成功,但界面显示不出来,是跨域问题?
      • ¥15 ANSYS APDL循环结果输出