This section describes how to use ifesle in the SQL Server Stored Procedure for your reference. There are two tables in the database. The primary key of Table A is automatically increased and the foreign key of Table B is allowed to be empty. Now, you need to insert data to table B through programming, however, in a program, null values cannot be assigned to the Int type. If no value is assigned, the default value is 0. To solve this problem
This section describes how to use if esle in the SQL server Stored Procedure for your reference. There are two tables in the database. The primary key of Table A is automatically increased and the foreign key of Table B is allowed to be empty. Now, you need to insert data to table B through programming, however, in a program, null values cannot be assigned to the Int type. If no value is assigned, the default value is 0. To solve this problem
This section describes how to use if esle in the SQL server Stored Procedure for your reference. There are two tables in the database. The primary key of Table A is automatically increased and the foreign key of Table B is allowed to be blank.
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:
The 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 ()