Home Forums SQL Server 7,2000 SQL Server Newbies How to update just the year in date fields (non datetime data type) RE: How to update just the year in date fields (non datetime data type)

  • Now I did a little testing with the BIGINT value to deteremine the maximum BIGINT value that could be converted to DATETIME as follows:

    DECLARE @b-2 BIGINT

    SET @b-2 = 2958457

    WHILE @b-2 < = 2958464

    BEGIN

    SELECT convert(VARCHAR(20),CAST(@B AS DATETIME),101),@B

    SET @b-2 = @b-2 + 1

    END

    The last value BEFORE the error message was: 2958463

    In your code if you will be attempting to convert a BIGINT value to a date use something like :

    SELECT convert(VARCHAR(20),CAST(@B AS DATETIME),101) WHERE @b-2 < 2958463

    In order to clarify or confuse here are the result of additional code.

    DECLARE @b-2 BIGINT

    SET @b-2 = 41046

    SELECT @b-2 AS 'Bigint',CAST(@B AS BINARY(8)) AS 'Binary 8',convert(VARCHAR(20)

    ,CAST(@B AS DATETIME),101) AS 'Date'

    SELECT CAST(GETDATE() AS BIGINT) AS 'Bigint'

    ,CAST(GETDATE() AS BINARY(8)) AS 'Binary 8',GETDATE() AS 'Date'

    Result:

    Bigint Binary 8 Date

    41046 0x000000000000A056 05/19/2012

    41046 0x0000A0560090F582 2012-05-19 08:47:46.780

    To clarify read more:

    http://www.sql-server-performance.com/2004/datetime-datatype/

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]