Hi all, played for a while with Hugo's example and ... look what I found :w00t:
First, I have tested and it errors on 2008, works on 2005.
So, the following applies to SQL Server 2008. Here is the script, note the results from selects in the end of the script:
USE [master]
GO
IF EXISTS (SELECT name FROM sys.databases WHERE name = N'Weird') BEGIN
ALTER DATABASE [Weird] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DROP DATABASE [Weird]
END
GO
CREATE DATABASE [Weird]
GO
-- set compatibility level
ALTER DATABASE [Weird] SET COMPATIBILITY_LEVEL = 90
GO
ALTER DATABASE [Weird] SET RECOVERY SIMPLE
GO
USE weird
go
SELECT ROUND(789.98,-3) AS WeirdCol
INTO WeirdTable;
-- 1 ok
SELECT COUNT(*) FROM WeirdTable
-- 2 doesn't work
SELECT WeirdCol FROM WeirdTable
--3 explicit cast works !!!
SELECT CAST(WeirdCol as decimal(6,2)) FROM WeirdTable
Now you have to admit that this is realy weird:hehe:
PS: If I had a blog this would probably be worth blogging about. Hugo?
Regards,
Hrvoje Piasevoli
Hrvoje Piasevoli