Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7595067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:34:43+00:00 2026-05-30T21:34:43+00:00

Is this a good candidate for a MERGE command? Must the source data also

  • 0

Is this a good candidate for a MERGE command?

Must the source data also be another table or can it be variables that are passed?

If it must be a table, is inserting the passed variables into a temp table sane?

Could you help me with the syntax?

CREATE PROCEDURE [dbo].[usp_ConvertToMerge]
    @GL_DT           date
    ,@SRC_SYS_ID     varchar(60)
    ,@MLR_SRC_SYS_CD char(3)
    ,@TRSRY_FEED_DT  date
    ,@Data           varchar(20)
AS
    BEGIN
        IF NOT EXISTS (SELECT
                           @GL_DT
                       FROM
                           MLR_REBATE_IBOR_INFO_2
                       WHERE
                          [GL_DT] = @GL_DT
                          AND [SRC_SYS_ID]      = @SRC_SYS_ID
                          AND [MLR_SRC_SYS_CD]  = @MLR_SRC_SYS_CD
                          AND [TRSRY_FEED_DT]   = @TRSRY_FEED_DT)
            BEGIN
                INSERT INTO [dbo].[MLR_REBATE_IBOR_INFO_2]
                            ([GL_DT],
                             [SRC_SYS_ID],
                             [MLR_SRC_SYS_CD],
                             [TRSRY_FEED_DT],
                             [Data])
                SELECT
                    @GL_DT
                    ,@SRC_SYS_ID
                    ,@MLR_SRC_SYS_CD
                    ,@TRSRY_FEED_DT
                    ,@Data

            END
        ELSE
            BEGIN
                UPDATE [dbo].[MLR_REBATE_IBOR_INFO_2]
                SET    [Data] = @Data
                WHERE  [GL_DT] = @GL_DT
                       AND [SRC_SYS_ID]         = @SRC_SYS_ID
                       AND [MLR_SRC_SYS_CD]     = @MLR_SRC_SYS_CD
                       AND [TRSRY_FEED_DT]      = @TRSRY_FEED_DT
            END
    END

GO 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:34:44+00:00Added an answer on May 30, 2026 at 9:34 pm

    I think I did it:

    CREATE PROCEDURE MyMergeTest
         @GL_DT             date
        ,@SRC_SYS_ID        char(20)     
        ,@MLR_SRC_SYS_CD    char(3)
        ,@TRSRY_FEED_DT     date
        ,@Data              varchar(20)
    AS
    BEGIN
    
        MERGE MLR_REBATE_IBOR_INFO_2 AS target
        USING 
            (
            SELECT 
                 @GL_DT
                ,@SRC_SYS_ID
                ,@MLR_SRC_SYS_CD            
                ,@TRSRY_FEED_DT
                ,@Data
            ) AS source 
            (
                 GL_DT
                ,SRC_SYS_ID
                ,MLR_SRC_SYS_CD            
                ,TRSRY_FEED_DT
                ,Data
            )
    
        ON (
            target.GL_DT            = source.GL_DT              AND
            target.SRC_SYS_ID       = source.SRC_SYS_ID         AND
            target.MLR_SRC_SYS_CD   = source.MLR_SRC_SYS_CD     AND
            target.TRSRY_FEED_DT    = source.TRSRY_FEED_DT 
            )
        WHEN MATCHED THEN 
            UPDATE SET Data = source.Data
        WHEN NOT MATCHED THEN   
            INSERT 
                (
                [GL_DT],
                [SRC_SYS_ID],
                [MLR_SRC_SYS_CD],
                [TRSRY_FEED_DT],
                [Data]
                )
            VALUES 
                (
                [GL_DT], --<<it looks like these can eiether be the variable eg, @GL_DT, or prefixed by 'source.'
                [SRC_SYS_ID],
                [MLR_SRC_SYS_CD],
                [TRSRY_FEED_DT],
                [Data]          
                );
    
    
    
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some nicely-structured data that looks like this: CREATE TABLE SourceBodyPartColors ( person_ID
This is a good candidate for the Works on My Machine Certification Program .
is this good code? can it be simplified somehow? SELECT u.id,u.title,u.title,u.first,u.last FROM (((tblusers u
I realised this might be relatively niche, but maybe that's why this is good
Asserts can't be caught. This is good because some errors I don't want to
I know that using GUID generated by newid isn't a good candidate for primary
Surprisingly can't find a match for my question. I have one table that I
I know there are emulators, but is this good enough? If someone is serious
This is good: import string string.capwords("proper name") Out: 'Proper Name' This is not so
Following this question: Good crash reporting library in c# Is there any library like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.