|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
--如下代码分享自用友时空牛人苹果 ,感谢苹果的奉献!
-
- declare @sql varchar(max),@aimtbname varchar(50),@sourcetbname varchar(50),@tbname varchar(50),@fdname varchar(50)
- set @sql = ''
- set @sourcetbname = 'tmp_dj_xsg212'
- set @aimtbname = 'jzorder_mx'
- set @tbname = ''
- set @fdname = ''
- --lixd 2011.4.2
- create table #t_aimstru(
- fdname char(20),
- fdtype char(50),
- length int,
- xprec int,
- xscale int
- )
- create table #t_maxlen(
- fdname char(20),
- length int
- )
- delete from #t_aimstru
- insert into #t_aimstru
- select b.name as fdname,c.name as fdtype,b.length,b.xprec,b.xscale
- from sysobjects a
- join syscolumns b on a.id = b.id
- join systypes c on b.xtype=c.xtype and b.xusertype=c.xusertype
- where a.xtype='U' and a.name = @aimtbname
- declare cur_maxlen cursor for
- select b.name as fdname
- from sysobjects a join syscolumns b on a.id = b.id
- join systypes c on b.xtype=c.xtype and b.xusertype=c.xusertype
- where a.xtype = 'U' and a.name = @sourcetbname and c.name in ('text','ntext','char','varchar','nchar','nvarchar')
- open cur_maxlen
- fetch next from cur_maxlen into @fdname
- delete from #t_maxlen
- while @@fetch_status =0
- begin
- set @sql = 'select '''+@fdname+''' as fdname, max(datalength(rtrim(substring('+@fdname+',1,500)))) from '+@sourcetbname
- insert into #t_maxlen exec(@sql)
- fetch next from cur_maxlen into @fdname
- end
- close cur_maxlen
- deallocate cur_maxlen
- select a.fdname,a.length as sourcelength, b.length as aimlength
- from #t_maxlen a join #t_aimstru b on a.fdname = b.fdname
- where b.fdtype in ('char','varchar','nchar','nvarchar') and isnull(a.length,0)-isnull(b.length,0) > 0
- drop table #t_aimstru, #t_maxlen
复制代码 |
|