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 6221133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:04:48+00:00 2026-05-24T08:04:48+00:00

I’ve found many other posts here on how to do this but unsure how

  • 0

I’ve found many other posts here on how to do this but unsure how to write the initial select statement which checks for the system name and the update statement since there is a temp table involved. I’m very green to working with stored procedures let alone temp tables so I’m at a loss. What I understand to be happening is data is fed to the SP via an XML feed (that step is not shown here). The data from the xml feed is then stored in a temp table. As the SP is written right now, the SP inserts the data from the temp table into the real table. I need to add a step that checks to see if the system name exists and if it does, update it and if it doesn’t, then insert it. I need help with the IF EXISTS select statement and the update query, please.

Here is the original statement which only consists of an insert.

original statement

insert into si_systemdetail(projectname, systemname, contactsbcuid, sdverifier, systemtype, location, proposedlivedate,  status, bkpsa, pripsa,platform)
   select 
        @project, systemname, contactsbcuid, sdverifier,systemtype, location, 
        proposedlivedate, 'Initial', bkpsa, pripsa, @platform
   from @systemInfo 
   where status in ('Production','Production w/o Appl') 
     and systemname not in (select systemname from si_systemdetail) 
     and @project is not null`

updated statement

IF EXISTS (select systemname from si_systemdetail WHERE systemname = (select systemname from @systemInfo where systemname in (select systemname from si_systemdetail) and @project is not null))  
BEGIN  
    -- update query
    UPDATE si_systemdetail
        SET  **I DO NOT KNOW HOW TO WRITE THIS SECTION**
    WHERE   
        systemname IN (select systemname from si_systemdetail)  
        AND @project is not null
END
ELSE
BEGIN
    -- Write your insert query
    insert into si_systemdetail(projectname, systemname, contactsbcuid, sdverifier, 
                systemtype, location, proposedlivedate,  status, bkpsa, pripsa, platform)
       select 
            @project, systemname, contactsbcuid, sdverifier,systemtype, location, 
            proposedlivedate, 'Initial', bkpsa, pripsa, @platform
       from @systemInfo 
       where status in ('Production','Production w/o Appl') 
         and systemname not in (select systemname from si_systemdetail) 
         and @project is not null
END
  • 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-24T08:04:49+00:00Added an answer on May 24, 2026 at 8:04 am

    You can save one query by simply attempting to run the UPDATE and then checking @@ROWCOUNT. If it is 0, you can try the INSERT. In SQL Server 2008 you could replace this messy logic with MERGE.

    UPDATE d
        SET d.projectname   = i.projectname,
            d.contactsbcuid = i.contactsbcuid,
    
            -- other columns here
    
            d.[platform]    = @platform
    FROM
        dbo.si_systemdetail AS d
        INNER JOIN @systemInfo AS i
        ON i.systemname     = d.systemname
    WHERE
        i.[status] IN ('Production', 'Production w/o Appl')
        AND @project IS NOT NULL;
    
    IF @@ROWCOUNT = 0
    BEGIN
        insert into ...
    END
    

    Not clear what you want to do when there is a match on systemname but @project is NULL or the [status] is not in those two values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.