SQL Server Stored Procedures

Source: Internet
Author: User

create proc Proc_test_insert  --If you want to modify this stored procedure, just change the Create to alter (@p_name nvarchar, @p_age int, @p_email varchar (+), @p_addres nvarchar, @p_remarks nvarchar [email protected] nvarchar out--to save the output error message, or success information  Asbegin If @p_email is null or Len (@p_email) <=0    print ' email cannot be empty '; else  if @p_addres is null or Len (@p_ad Dres) <=0  print ' address cannot be empty '  else  begin    INSERT INTO t_test values (@p_name, @p_age, @p_email, @p_addres, @p_remarks)   print ' Insert succeeded '  endend     exec proc_test_insert  ' Wu Song ', "," [email protected] ', ', '    -- Insert will not succeed, error: "Address cannot be empty"


Or you can do it.

create proc Proc_test_insert  --If you want to modify this stored procedure, just change the Create to alter  (@p_name nvarchar, @p_age int, @p_email varchar (+), @p_addres nvarchar, @p_remarks nvarchar, @num nvarchar out--to save the output error message, or success information  ) Asbeginset @num = "; If @p_email is null or Len (@p_email) <=0    Set @num = ' Email cannot be empty '; else  if @p_addres is null or Len (@p_addres) <= 0  Set @num = ' address cannot be empty '  else  begin    INSERT INTO t_test values (@p_name, @p_age, @p_email, @p_addres, @p_ Remarks)   Set @num = ' Insert succeeded '  endend   declare @num nvarchar (); Exec proc_test_insert  ' Lu Zhishen ', 45, ', ' Shandong province Jining Liangshan County ', ', @num out  --insert will not succeed, will error: "Email cannot be empty" print @num


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.