Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009
    Posts
    1

    Unanswered: Stored Procedure

    I am trying to create a stored procedure that will loop through a staging table and once data is found check to see if the data exist using a function if not then insert into a production table.

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    MERGE would do the same in a single statement
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool Merge it

    Try the MERGE statement, kind like this:
    Code:
    MERGE INTO MyTable T
      USING (SELECT * FROM StagingTable) S
         ON T.PK = S.PK
    WHEN NOT MATCHED THEN
      INSERT (T.col1, T.col2, T.col3)
      VALUES (S.col3, S.col2, S.col1)
       WHERE  S.col4 = 'DATA EXISTS';
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •