MERGE Statement and compatibility_level

  • Hi,

    I want to merge two tables from different databases.

    i'm using the following code

    MERGE Client.dbo.ClientTbl_Product AS pdt

    USING (SELECT * FROM s1_Staging.dbo.ClientTbl_Product) AS SPdt

    ON pdt.ProductKey = SPdt.ProductKey and pdt.[ProductId]=Spdt.[ProductId]

    and pdt.[Retailerkey] = Spdt.[Retailerkey]

    WHEN MATCHED THEN UPDATE

    SET pdt.[Description] =Spdt.[Description]

    ,pdt.[ProductHierarchyId] = Spdt.[ProductHierarchyId]

    ,pdt.[SKUNumber] = Spdt.[SKUNumber]

    WHEN NOT MATCHED THEN

    INSERT Description

    ,ProductHierarchyId

    ,SKUNumber

    values

    (

    SPdt.Description

    ,SPdt.ProductHierarchyId

    ,SPdt.SKUNumber

    )

    i'm getting the following error:

    Msg 325, Level 15, State 1, Line 3

    Incorrect syntax near 'MERGE'. You may need to set the compatibility level of the current database to a higher value to enable this feature. See help for the SET COMPATIBILITY_LEVEL option of ALTER DATABASE.

    Msg 156, Level 15, State 1, Line 4

    Incorrect syntax near the keyword 'AS'.

    i've gone for the folloing code to solve this

    ALTER DATABASE s1_Staging

    SET COMPATIBILITY_LEVEL = 100

    ALTER DATABASE Admin

    SET COMPATIBILITY_LEVEL = 100

    after this also i'm getting the same error.

    How to go about it. Early help would be highly appreciated.

    Thanks,

    Regards

    Anamika

  • The compatibility level of the database context you are using while executing the statement, might be less than 100.

    When running Merge statement, first make sure to use the database with compatibility level 100.

    So, in your case, you should be doing the following:

    Use <database with compatibility level 100>

    GO

    Merge .....

    :

    :

    :

    GO

    Hope this Helps!

    Swapna

  • I got almost similar problem and escaped through by writing following script:

    [font="Courier New"]

    ALTER DATABASE dbKAR

    SET COMPATIBILITY_LEVEL = 100

    GO

    [/font]

    Muhammad Kanwal Shehzad

    kanwalshehzad@gmail.com

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

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