Now we want to insert data to table B through programming, but in the program, it is not allowed to assign null values to the Int type. If no value is assigned, the default value is 0.
To solve this problem, If Else of the stored procedure is used. The following describes the complete stored procedure.
Sample Code:
Copy codeThe Code is 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 ()