sql经常会遇到“将截断二进制或字符串”的错误——处理办法


sql经常会遇到“将截断二进制或字符串”的错误——处理办法

1、修改列长度——无法定位具体字段

2、程序逻辑中增加判断,以定位具体字段

 

由于我是在报表数据库中直接写SQL,没有校验逻辑,所以想把全部字段的长度都增加到最大。写了批量脚本:

declare c cursor for select name, max_length from sys.all_columns where object_id= object_id('tablename') and system_type_id=231

open c

declare @cName varchar(100),@maxLength int

fetch next from c into @cName, @maxLength
while @@FETCH_STATUS=0
begin
    declare @sql nvarchar(max)
    set @sql = 'alter table tablename alter column ' + @cName + ' nvarchar(max)'
    exec(@sql)

    fetch next from c into @cName, @maxLength
end

close c
deallocate c

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM