We Recommend

SQL Cookbook SQL Cookbook
Written in O'Reilly's popular Problem/Solution/Discussion style, the SQL Cookbook is sure to please. Anthony's credo is: "When it comes down to it, we all go to work, we all have bills to pay, and we all want to go home at a reasonable time and enjoy what's still available of our days." The SQL Cookbook moves quickly from problem to solution, saving you time each step of the way.


Posted By

grogi on 04/17/08


Tagged

person


Versions (?)


proba


Published in: SQL 


Stored procedure for adding new person.


  1. CREATE procedure [dbo].[add_new_person]
  2. (
  3. -- Input Parametars
  4. @embg varchar(20),
  5. @first_name nvarchar(30),
  6. @last_name nvarchar(50),
  7. @username nvarchar(30),
  8. @password nvarchar(30),
  9. @address nvarchar(50) = NULL,
  10. @city nvarchar(30) = NULL,
  11. @birth_date datetime = NULL,
  12. @birth_place nvarchar(30) = NULL
  13. ) AS
  14. begin
  15.  
  16. IF NOT EXISTS (SELECT 1 FROM person WHERE embg = @embg)
  17. INSERT INTO person
  18. (embg, first_name, last_name, username, password, address, city, birth_date, birth_place)
  19. VALUES
  20. (@embg, @first_name, @last_name, @username, @password, @address, @city, @birth_date, @birth_place)
  21. else
  22. UPDATE person
  23. SET first_name = @first_name,
  24. last_name = @last_name,
  25. username = @username,
  26. password = @password,
  27. address = @address,
  28. city = @city,
  29. birth_date = @birth_date,
  30. @birth_place = @birth_place
  31. WHERE embg = @embg
  32.  
  33. end
  34. go

Report this snippet 

You need to login to post a comment.