sql server - IF NOT EXISTS SQL Statement -


I am quite new in SQL I am trying to write a stored procedure which will check that the 'Alias' in the table And if so, return the details; If it does not exist, then it will add it. At the moment I have got 50% work, but this nickname will not return the details if it does not exist

  DECLARE @Alias ​​VARCHAR (max) IF (Select * from [user ] Enter the values ​​(@ alias, 'uk', 'user') < P> Can anyone tell me where am I wrong?  

Thank you in advance

Tom

it seems that you Why do not you just force them:

  Create unique index users_alias on user (surname);  

or if you If you really want to do this through a query, use a select-in:

  INSERT [user] ([nickname], [country], [role]) @ Alias, 'uk', 'user' (selection 1) does not exist dual (select * from [user] where [alias] = @ alias]  

Selection of the query returns to the 1st row if there is no user already with the alias, or if a row is not otherwise.

To get some ideas: You do not need a stored procedure to do this. Br> To think more: You do not need all the stores in the store.
To think more: The stored procedure can actually be done


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -