Usage instances of if else in SQL Server stored procedures _mssql

Source: Internet
Author: User

Now you can programmatically insert data into table B, but in your program you are not allowed to assign null values to the INT type if you do not assign a value to default to 0.
To solve this problem, the if Else of the stored procedure is used, and the following is the complete stored procedure.

code example:

Copy Code code as follows:

Create PROCEDURE [dbo]. [P_form_control_info_add]
@TypeName varchar (20),
@Description varchar (50),
@CtlColSpan int,
@Sort int,
@SourceID int,
@FieldID int,
@TableID int
As
If @SourceID = 0
Begin
INSERT into T_form_control_info (
[TypeName],
[Description],
[Ctlcolspan],
[Sort],
[FieldID],
[TableID]
) VALUES (
@TypeName,
@Description,
@CtlColSpan,
@Sort,
@FieldID,
@TableID
)
End
Else
Begin
INSERT into T_form_control_info (
[TypeName],
[Description],
[Ctlcolspan],
[Sort],
[SourceID],
[FieldID],
[TableID]
) VALUES (
@TypeName,
@Description,
@CtlColSpan,
@Sort,
@SourceID,
@FieldID,
@TableID
)
End
Return scope_identity ()

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.