• Now that I am at my desk I tested some stuff with your functions and I can't reproduce the issues you are seeing.

    I did however make some adjustments to your scalar function that will make it a little faster and simpler.

    Here is my proposed version.

    CREATE FUNCTION [dbo].[fn_get_pst_datetime] (@serverdatetime datetime = NULL)

    RETURNS datetime WITH SCHEMABINDING

    AS

    BEGIN

    RETURN dateadd(hour, -1, ISNULL(@serverdatetime, GETDATE()))

    END

    Then here is the code I used to test:

    CREATE TABLE testfunc (checkdate datetime)

    --Checked designer here all is fine

    INSERT INTO testfunc (checkdate)

    SELECT dbo.fn_get_pst_datetime(DEFAULT)

    --Checked designer here all is still fine

    ALTER TABLE [dbo].[testfunc] ADD CONSTRAINT [DF_testfunc_checkdate] DEFAULT (dbo.fn_get_pst_datetime(DEFAULT)) FOR [checkdate]

    --Checked designer here all is still fine

    INSERT INTO testfunc (checkdate)

    SELECT dbo.fn_get_pst_datetime(DEFAULT)

    --Checked designer here all is still fine

    Digging around the web it sounds like many people have run into the issue you are facing when there is a corrupt index on the base table. Obviously the table you posted here is an example and not the actual table you were having issues with.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/