• Hugo Kornelis (9/1/2010)


    webrunner (9/1/2010)


    DECLARE @a INT

    DECLARE @b-2 DATETIME

    SET @a = @b-2

    The above code executed successfully for me in SQL 2005 but gave the error listed in the answer when I ran it in SQL 2000**. So I think it is dependent on the SQL version, at least in the form expressed above.

    Which version of SQL Server 2005? When I run it, I get "Msg 257, Level 16, State 3, Line 3

    Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query."

    (I am using Microsoft SQL Server 2005 - 9.00.4053.00)

    Sorry, my mistake. (BTW, My SQL 2005 is version 9.0.3080.)

    This code runs OK in both versions:

    DECLARE @a INT

    DECLARE @b-2 DATETIME

    SET @b-2 = @a

    This code throws an error in both versions:

    DECLARE @a INT

    DECLARE @b-2 DATETIME

    SET @a = @b-2

    I mixed up the "SET @a = @b-2" version with the "SET @b-2= @a" version in my earlier post. I seem to have run one version in SQL 2000 and the other in SQL 2005.

    Attention to detail, anyone? :hehe:

    Thanks,

    webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html