Date Expression For Temporal Table

  • Apologies if this has already been asked, but I can't find a similar topic. I have a system-versioned table that I want to query for changes since 'yesterday'. All the examples I've found use either a literal or a variable that has been set to the required date/time. I'd like to be able to use code similar to that below, but the syntax isn't accepted.

    SELECT client_code, member_id
    FROM dbo.ds_client_member
    FOR SYSTEM_TIME AS OF DATEADD(day, -1, getdate())

    If anyone has working examples of something similar, I'd be interested to see them.
    Thanks.

  • You can use a variable in the SYSTEM_TIME AS OF clause, so if you declare and set the value of the variable at the beginning, that should work for you.

    John

  • John Mitchell-245523 - Monday, November 20, 2017 9:09 AM

    You can use a variable in the SYSTEM_TIME AS OF clause, so if you declare and set the value of the variable at the beginning, that should work for you.

    John

    I'm using a tool that generates the stored procedure. It has a box in which I can enter the FROM and WHERE clauses, but I don't have anywhere to declare and set the variable. I can modify the generated code, but then that has to be done every time anything else is changed. It seems odd that the AS OF clause doesn't accept any expression that results in the appropriate datatype.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply