title: T-SQL : If login failed, then sql
body: <p>Goal: Write a T-SQL statement that checks for login permissions on a linked server db, and then updates a column value based on login result.</p>
  
  <p>Sudo-ish code:</p>
  
  <pre><code>@Source = linked server connection string
  
  while true
  
  if exists(select [Something] from [@Source])
  update [Table] set [Column] = 1
  else
  update [Table] set [Column] = 0
  
  @Source = next linked server
  </code></pre>
  
  <p>The idea is that if I cannot get a record from the table, then I do not have access. When I execute this query using actual T-SQL, the login failed error occurs Is there any was of accomplishing this, using T-SQL? Currently I manually check and update.</p>