title: SQL Server Stored Procedure for Inserting or updating database
body: <p>I am new to stored procedures and trying to learn things. I have a database table which looks likes this,</p>
  
  <pre><code> Acc   | Room |  ID | Name |  Email | Status |  Date  | Number 
  =======+======+=====+======+========+========+========+========
  (null) |  101 | 001 |  ABC | (null) |   EMP  | (null) | (null) 
  (null) |  102 | 002 |  DEF | (null) |   TMP  | (null) | (null)   
  </code></pre>
  
  <p>I am creating a stored procedure to insert or update the data in the database depending on the ID. Not all the records has data to be inserted or updated.</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[uspInsertorUpdate]
      @room char(35),
      @id char(12),
      @name varchar(64),
      @status varchar(50),
  AS
  BEGIN
      SET NOCOUNT ON;
      IF EXISTS (SELECT null FROM emp WHERE ID = @id)
      BEGIN
         UPDATE emp 
         SET Room = @room, ID = @id, Name = @name, Status = @status
         WHERE ID = @id
      END
  
      INSERT INTO emp (Room, ID, Name, Status)
      VALUES(@room, @id, @name, @status);
  END
  </code></pre>
  
  <p>Not sure if this is correct, will this create the other records with null.</p>