sqlserver 存储过程中If Else的用法实例

现在要通过编程向B表中插入数据,可是在程序中是不允许给Int类型赋空值的如果不赋值就认为0。
为了解决这个问题,用到了存储过程的If Else,下面是完整的存储过程。

代码示例:

代码如下:
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],
[SourceID],
@SourceID,
@TableID
)
end
return ScopE_IDENTITY()

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...