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],

    [description],

    [ctlcolspan],

    [sort],

    [sourceid],

    [fieldid],

    [tableid]

) values (

    @typename,

    @description,

    @ctlcolspan,

    @sort,

    @sourceid,

    @fieldid,

    @tableid

)

end

return scope_identity()

(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐