title: Openquery SQL how to check if exists?
body: <p>I am using sql <code>OPENQUERY</code> to check if record exist passing parameter update it, if not insert a new record.</p>
  
  <p>Here is what I have so far</p>
  
  <pre><code>DECLARE @sql VARCHAR (8000)
  DECLARE @Id VARCHAR(20)
  
  SET @Id= '31124'
  
  SET @sql = '
  SELECT * FROM OPENQUERY
  (
     SERVERNAME, 
     ''
     SELECT Name FROM table WHERE Id= ''''' + @Id +  ''''' 
     ''
  )'
  EXEC (@sql)
  </code></pre>