To introduce you to the use of if esle in SQL Server stored procedures for your reference. There are two tables in the database, the primary key for table A is automatically growing and is the foreign key of table B and is allowed to be empty
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,
@Description varchar ( ,
@CtlColSpan int,
@Sort int,
@SourceID int,
@FieldID int,
@TableID int
as
if @SourceID = 0
Begin
INSERT Into T_form_control_info (
[TypeName],
[Description],
& nbsp [Ctlcolspan],
[Sort],
[FieldID],
[TableID]
) VALUES (
@TypeName,
@Description,
@CtlColSpan,
@Sort,
@FieldID,
@TableID
)
End
Else br> begin
INSERT into T_form_control_info (
[TypeName],
[Description] , the
[Ctlcolspan],
[Sort],
[SourceID],
[FieldID],
[TableID]
) VALUES (
@TypeName,
@Description,
@CtlColSpan,
@Sort,
@SourceID,
@FieldID,
@TableID
)
End
Return scope_identity ()