title: IF NOT EXISTS SQL Statement
body: <p>I'm fairly new to SQL. I'm trying to write a stored procedure that will check if the 'alias' is in the table, and if so return the details; if it doesn't exist it will add it. At the moment I've got it 50% working but it won't return the alias details if it does exist</p>
  
  <pre><code>DECLARE @Alias VARCHAR(MAX)
  
  IF NOT EXISTS(SELECT * FROM [Users] where [Alias] = @Alias)
     INSERT INTO [Users] ([Alias], [Country], [Role]) 
     VALUES (@Alias, 'UK', 'User')
  </code></pre>
  
  <p>Can anyone tell me where I'm going wrong?</p>
  
  <p>Thanks in advance</p>
  
  <p>Tom</p>