--查询nvarchar(max)的表和字段
select 'insert into #tempTabelInfo select '''+d.name+''', '''+a.name+''', max(len('+a.name+')) as '+d.name+'的'+a.name+' from '+d.name+' with(nolock) ' , d.name as tabelname,a.name,b.name FROM syscolumns a,
systypes b,sysobjects d
WHERE a.xtype=b.xusertype and a.id=d.id
and d.xtype='U' and a.length<0