Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Stats script not able to run on SQL Server 2005
Message
 
 
To
01/03/2010 21:33:37
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01451878
Message ID:
01451879
Views:
56
This message has been marked as the solution to the initial question of the thread.
>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?

The first thought, that comes to mind without even running this script, is to expand the values, e.g. instead of varchar(128) use, say, varchar(400).
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform