In order to benefit of SMO objects on SQL Server 2005, I have installed SQLSysClrTypes and SharedManagementObjects on a specific server. So, now, I can benefit of SMO objects and do some fancy things. I should now be also able to execute a stats script I have to obtain WA_Statistics information. The script is as follow:
SET ANSI_WARNINGS OFF
if object_ID('TempDB..#Stats') is not null
drop table #Stats
create table #Stats (TableName varchar(128), Statistics_Name varchar(128), Statistics_Keys varchar(128))
if object_ID('TempDB..#Stats_Temp') is not null
drop table #Stats_Temp
create table #Stats_Temp (Statistics_Name varchar(128), Statistics_Keys varchar(128))
exec sp_MSforeachtable
'insert into #Stats_Temp execute sp_helpstats ''?'', ''ALL''','?',
'insert into #Stats select ''?'', * from #Stats_Temp','delete from #Stats_Temp'
select * from #Stats where Statistics_Name like '_WA%'
Now, with the two Microsoft program installed, I can run this script. However, on a SQL Server 2005, it gives an error:
"Msg 8152, Level 16, State 2, Procedure sp_helpstats, Line 101
String or binary data would be truncated."
I haven't been able to figure out what I could adjust to have this script to be compliant on both versions. I know it is related to the fact that it runs on SQL Server 2005. So, I would need to adjust one more thing. Anyone would be able to know what it is exactly?